Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 0.25 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Does Ruby 1.8 have an equivalent to 1.9's __callee__?
  2. def foo
  3.   this_method = __callee__  # => 'foo'
  4. end
  5.        
  6. module Kernel
  7.   # Defined in ruby 1.9
  8.   unless defined?(__callee__)
  9.     def __callee__
  10.       caller[0] =~ /`([^']*)'/ and $1
  11.     end
  12.   end
  13. end