Module: Kernel

Defined in:
lib/backports/1.9/kernel.rb,
lib/backports/1.8.7/kernel.rb,
lib/backports/rails/kernel.rb

Defined Under Namespace

Classes: StopIteration

Instance Method Summary collapse

Instance Method Details

#__callee__Object



2
# File 'lib/backports/1.9/kernel.rb', line 2

alias_method :__callee__, :__method__

#__method__Object



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

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

#define_singleton_method(*args, &block) ⇒ Object

Standard in ruby 1.8.7+. See official documentation



9
10
11
12
13
# File 'lib/backports/1.8.7/kernel.rb', line 9

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

#instance_exec(*arg, &block) ⇒ Object

Standard in ruby 1.8.7+. See official documentation



16
17
18
19
# File 'lib/backports/1.8.7/kernel.rb', line 16

def instance_exec(*arg, &block)
  define_singleton_method(:"temporary method for instance_exec", &block)
  send(:"temporary method for instance_exec", *arg)
end

#loop_with_stop_iteration(&block) ⇒ Object



25
26
27
28
29
# File 'lib/backports/1.8.7/kernel.rb', line 25

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

#require_relative(relative_feature) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/backports/1.9/kernel.rb', line 4

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(relative_feature, File.dirname(file))
end

#returning(obj) {|obj| ... } ⇒ Object

Standard in rails. See official documentation

Yields:

  • (obj)


8
9
10
11
# File 'lib/backports/rails/kernel.rb', line 8

def returning(obj)
  yield obj
  obj
end

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

Standard in ruby 1.8.7. See official documentation

Yields:

  • (_self)

Yield Parameters:

  • _self (Kernel)

    the object that the method was called on



34
35
36
37
# File 'lib/backports/1.8.7/kernel.rb', line 34

def tap
  yield self
  self
end

#try(method_id, *args, &block) ⇒ Object

Standard in rails. See official documentation



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

def try(method_id, *args, &block)
  send(method_id, *args, &block) unless self.nil?
end