Module: Kernel
- Defined in:
- lib/sixarm_ruby_ramp/kernel.rb
Overview
Kernel extensions
Class Method Summary collapse
-
.pp_s(*objs) ⇒ String
Pretty print to a string.
Instance Method Summary collapse
-
#caller_method_name(caller_index = 0) ⇒ String
See: - www.ruby-forum.com/topic/75258 - In 1.9 (Ruby CVS HEAD) there is #__method__ and #__callee__ - eigenclass.org/hiki.rb?Changes+in+Ruby+1.9#l90 - Make this fast because its often doing logging & reporting.
-
#my_method_name ⇒ String
See: - www.ruby-forum.com/topic/75258 - In 1.9 (Ruby CVS HEAD) there is #__method__ and #__callee__ - eigenclass.org/hiki.rb?Changes+in+Ruby+1.9#l90.
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
79 80 81 82 83 84 85 86 |
# File 'lib/sixarm_ruby_ramp/kernel.rb', line 79 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:
-
In 1.9 (Ruby CVS HEAD) there is #__method__ and #__callee__
- Make this fast because its often doing logging & reporting. Inline this and use $1 because it’s empirically faster than /1
These two methods must always be equal:
caller_method_name(0) === my_method_name
60 61 62 63 64 |
# File 'lib/sixarm_ruby_ramp/kernel.rb', line 60 def caller_method_name(caller_index=0) RUBY_VERSION > '2.0' \ ? caller_locations(caller_index + 1,1).first.base_label \ : caller[caller_index][/`([^']*)'/, 1] end |
#my_method_name ⇒ String
See:
-
In 1.9 (Ruby CVS HEAD) there is #__method__ and #__callee__
See stackoverflow.com/questions/5100299/how-to-get-the-name-of-the-calling-method
Make this fast because its often doing logging & reporting. Inline this and use $1 because it’s empirically faster than /1
These two methods must always be equal:
caller_method_name(0) === my_method_name
31 32 33 34 35 |
# File 'lib/sixarm_ruby_ramp/kernel.rb', line 31 def my_method_name RUBY_VERSION > '2.0' \ ? caller_locations(1,1).first.base_label \ : caller[0][/`([^']*)'/, 1] end |