Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created November 3, 2011 15:06
Show Gist options
  • Select an option

  • Save pasberth/1336718 to your computer and use it in GitHub Desktop.

Select an option

Save pasberth/1336718 to your computer and use it in GitHub Desktop.
実行時に動的に関数名を得る
module Kernel
def funcname
caller[0] =~ /^.*?\:in `(.*?)'$/
$1.to_sym
end
end
if __FILE__ == $PROGRAM_NAME
require "test/unit"
class T < Test::Unit::TestCase
def test_0
assert_equal :test_0, funcname
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment