Module: Kernel

Defined in:
lib/webget_ruby_ramp/kernel.rb

Overview

Kernel extensions

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pp_s(*objs) ⇒ String

Pretty print to a string.

Created by Graeme Mathieson.

See rha7dotcom.blogspot.com/2008/07/ruby-and-rails-how-to-get-pp-pretty.html

Examples:

pp_s(["foo","goo"])
=> "[\"foo\", \"goo\"]\n"

Returns:

  • (String)

    a pretty print string of the params



74
75
76
77
78
79
80
81
# File 'lib/webget_ruby_ramp/kernel.rb', line 74

def pp_s(*objs)  
  str = StringIO.new  
  objs.each {|obj|  
      PP.pp(obj, str)  
    }  
    str.rewind  
    str.read  
end

Instance Method Details

#caller_method_name(caller_index = 0) ⇒ String

See:

- Make this fast because its often doing logging & reporting. Inline this and use $1 because it’s empirically faster than /1

These two methods are always equal:

caller_method_name(0) === my_method_name

Examples:

def foo
  puts caller_method_name(0)
  puts caller_method_name(1)
end
=> 
"foo"
"irb_binding"

Returns:

  • (String)

    the method name of the caller at the index



57
58
59
# File 'lib/webget_ruby_ramp/kernel.rb', line 57

def caller_method_name(caller_index=0)
  caller[caller_index] =~ /`([^']*)'/ and $1
end

#my_method_nameString

See:

- Make this fast because its often doing logging & reporting. Inline this and use $1 because it’s empirically faster than /1

These two methods are always equal:

caller_method_name(0) === my_method_name

Examples:

def foo
  puts my_method_name
end
foo
=> "foo"

Returns:



30
31
32
# File 'lib/webget_ruby_ramp/kernel.rb', line 30

def my_method_name
  caller[0] =~ /`([^']*)'/ and $1
end