Skip to content

Instantly share code, notes, and snippets.

@alloy-d
Created December 3, 2012 19:23
Show Gist options
  • Save alloy-d/4197282 to your computer and use it in GitHub Desktop.
Save alloy-d/4197282 to your computer and use it in GitHub Desktop.
Fun with Ruby Procs and the stack.
module AwarenessUtils
# Example: `define_method :current_method_name, StackWalker.new(2)`
class StackWalker < Proc
def self.new(depth=1)
super() { instance_eval { caller[depth] =~ /`(.+)'/ and $1 } }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment