module Kernel
def __method__
def __method__ m = caller(1).first[/`(.*)'/,1] m.to_sym if m end
def define_singleton_method(*args, &block)
def define_singleton_method(*args, &block) class << self self end.send(:define_method, *args, &block) end
def instance_exec(*arg, &block)
def instance_exec(*arg, &block) class << self self end.send(:define_method, :"temporary method for instance_exec", &block) send(:"temporary method for instance_exec", *arg) end
def lambda_with_lambda_tracking(&block)
def lambda_with_lambda_tracking(&block) l = lambda_without_lambda_tracking(&block) l.send :__is_lambda__=, true unless block.send(:__is_lambda__) == false l end
def loop_with_stop_iteration(&block)
def loop_with_stop_iteration(&block) loop_without_stop_iteration(&block) rescue StopIteration # ignore silently end
def method_with_additional_info(name)
def method_with_additional_info(name) bound = method_without_additional_info(name) bound.name = name.to_s bound.receiver = self bound.owner = self.class.ancestors.find{|mod| mod.instance_methods(false).include? bound.name} bound end
def proc_with_lambda_tracking(&block)
def proc_with_lambda_tracking(&block) l = proc_without_lambda_tracking(&block) l.send :__is_lambda__=, block.send(:__is_lambda__) == true l end
def public_method(meth)
def public_method(meth) if respond_to?(meth) && !protected_methods.include?(meth.to_s) method(meth) else raise NameError, "undefined method `#{meth}' for class `#{self.class}'" end end
def public_send(method, *args, &block)
def public_send(method, *args, &block) if respond_to?(method) && !protected_methods.include?(method.to_s) send(method, *args, &block) else :foo.generate_a_no_method_error_in_preparation_for_method_missing rescue nil # otherwise a NameError might be raised when we call method_missing ourselves method_missing(method.to_sym, *args, &block) end end
def require_relative(relative_feature)
def require_relative(relative_feature) file = caller.first.split(/:\d/,2).first if /\A\((.*)\)/ =~ file # eval, etc. raise LoadError, "require_relative is called in #{$1}" end require File.expand_path(Backports.convert_path(relative_feature), File.dirname(file)) end
def require_with_backports(lib)
def require_with_backports(lib) begin return false unless require_without_backports(lib) paths = Backports::StdLib.extended_lib.fetch(lib, nil) rescue LoadError return false if Backports::StdLib::LoadedFeatures.new.include?(lib) raise unless paths = Backports::StdLib.extended_lib.fetch(lib, nil) Backports::StdLib::LoadedFeatures.mark_as_loaded(lib) end if paths paths.each do |path| require_without_backports(path) end end true end
def singleton_class
def singleton_class class << self; self; end end
def tap
def tap yield self self end