Module: Kernel

Defined in:
lib/backports/std_lib.rb,
lib/backports/1.8.7/kernel/tap.rb,
lib/backports/1.8.7/method/name.rb,
lib/backports/1.9.1/proc/lambda.rb,
lib/backports/2.6.0/kernel/then.rb,
lib/backports/2.2.0/kernel/itself.rb,
lib/backports/1.8.7/stop_iteration.rb,
lib/backports/1.8.7/kernel/__method__.rb,
lib/backports/1.9.1/kernel/__callee__.rb,
lib/backports/2.5.0/kernel/yield_self.rb,
lib/backports/1.9.1/kernel/public_send.rb,
lib/backports/1.8.7/kernel/instance_exec.rb,
lib/backports/1.9.1/kernel/public_method.rb,
lib/backports/1.9.2/kernel/singleton_class.rb,
lib/backports/1.9.1/kernel/require_relative.rb,
lib/backports/1.9.1/kernel/define_singleton_method.rb

Instance Method Summary collapse

Instance Method Details

#__method__Object Also known as: __callee__



3
4
5
6
# File 'lib/backports/1.8.7/kernel/__method__.rb', line 3

def __method__
  m = caller(1).first[/`(.*)'/,1]
  m.to_sym if m
end

#define_singleton_method(*args, &block) ⇒ Object



3
4
5
6
7
# File 'lib/backports/1.9.1/kernel/define_singleton_method.rb', line 3

def define_singleton_method(*args, &block)
  class << self
    self
  end.send(:define_method, *args, &block)
end

#instance_exec(*arg, &block) ⇒ Object



3
4
5
6
7
8
# File 'lib/backports/1.8.7/kernel/instance_exec.rb', line 3

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

#itselfObject



3
4
5
# File 'lib/backports/2.2.0/kernel/itself.rb', line 3

def itself
  self
end

#lambda_with_lambda_tracking(&block) ⇒ Object



25
26
27
28
29
# File 'lib/backports/1.9.1/proc/lambda.rb', line 25

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

#loop_with_stop_iteration(&block) ⇒ Object



7
8
9
10
11
# File 'lib/backports/1.8.7/stop_iteration.rb', line 7

def loop_with_stop_iteration(&block)
  loop_without_stop_iteration(&block)
rescue StopIteration
  # ignore silently
end

#method_with_additional_info(name) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/backports/1.8.7/method/name.rb', line 30

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

#proc_with_lambda_tracking(&block) ⇒ Object



31
32
33
34
35
# File 'lib/backports/1.9.1/proc/lambda.rb', line 31

def proc_with_lambda_tracking(&block)
  l = proc_without_lambda_tracking(&block)
  l.send :__is_lambda__=, block.send(:__is_lambda__) == true
  l
end

#public_method(meth) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/backports/1.9.1/kernel/public_method.rb', line 3

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) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/backports/1.9.1/kernel/public_send.rb', line 3

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) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/backports/std_lib.rb', line 10

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

#singleton_classObject



3
4
5
# File 'lib/backports/1.9.2/kernel/singleton_class.rb', line 3

def singleton_class
  class << self; self; end
end

#tap {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Kernel)

    the object that the method was called on



3
4
5
6
# File 'lib/backports/1.8.7/kernel/tap.rb', line 3

def tap
  yield self
  self
end

#thenObject



5
# File 'lib/backports/2.6.0/kernel/then.rb', line 5

alias_method :then, :yield_self

#yield_self {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Kernel)

    the object that the method was called on



2
3
4
5
# File 'lib/backports/2.5.0/kernel/yield_self.rb', line 2

def yield_self
  return to_enum(__method__) { 1 } unless block_given?
  yield self
end