module Kernel

Public Instance Methods

__callee__() click to toggle source
Alias for: __method__
__method__() click to toggle source
# File lib/backports/1.8.7/kernel.rb, line 3
def __method__
  m = caller(1).first[%r`(.*)'/,1]
  m.to_sym if m
end
Also aliased as: __callee__
define_singleton_method(*args, &block) click to toggle source

Standard in ruby 1.9. See official documentation

# File lib/backports/1.9.1/kernel.rb, line 5
def define_singleton_method(*args, &block)
  class << self
    self
  end.send(:define_method, *args, &block)
end
instance_exec(*arg, &block) click to toggle source

Standard in ruby 1.8.7+. See official documentation

# File lib/backports/1.8.7/kernel.rb, line 9
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
lambda_with_lambda_tracking(&block) click to toggle source
# File lib/backports/1.9.1/proc.rb, line 19
def lambda_with_lambda_tracking(&block)
  Backports.track_lambda block, lambda_without_lambda_tracking(&block), true
end
loop_with_stop_iteration(&block) click to toggle source
# File lib/backports/1.8.7/kernel.rb, line 29
def loop_with_stop_iteration(&block)
  loop_without_stop_iteration(&block)
rescue StopIteration
  # ignore silently
end
method_with_additional_info(name) click to toggle source
# File lib/backports/1.8.7/method.rb, line 28
def method_with_additional_info(name)
  method_without_additional_info(name).tap do |bound|
    bound.name = name.to_s
    bound.receiver = self
    bound.owner = self.class.ancestors.find{|mod| mod.instance_methods(false).include? bound.name}
  end
end
proc_with_lambda_tracking(&block) click to toggle source
# File lib/backports/1.9.1/proc.rb, line 23
def proc_with_lambda_tracking(&block)
  Backports.track_lambda block, proc_without_lambda_tracking(&block)
end
public_method(meth) click to toggle source

Standard in ruby 1.9. See official documentation

# File lib/backports/1.9.1/kernel.rb, line 22
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
public_send(method, *args, &block) click to toggle source

Standard in ruby 1.9. See official documentation

# File lib/backports/1.9.1/kernel.rb, line 31
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
require_with_backports(lib) click to toggle source
# File lib/backports/tools.rb, line 312
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
returning(obj) { |obj| ... } click to toggle source

Standard in rails. See official documentation

# File lib/backports/rails/kernel.rb, line 8
def returning(obj)
  yield obj
  obj
end
singleton_class() click to toggle source
# File lib/backports/1.9.2/kernel.rb, line 2
def singleton_class
  class << self; self; end
end
tap() { |self| ... } click to toggle source

Standard in ruby 1.8.7. See official documentation

# File lib/backports/1.8.7/kernel.rb, line 17
def tap
  yield self
  self
end
try(method_id, *args, &block) click to toggle source

Standard in rails. See official documentation

# File lib/backports/rails/kernel.rb, line 3
def try(method_id, *args, &block)
  send(method_id, *args, &block) unless self.nil?
end