Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created February 18, 2009 06:47
Show Gist options
  • Save jugyo/66232 to your computer and use it in GitHub Desktop.
Save jugyo/66232 to your computer and use it in GitHub Desktop.
class Foo
def define_singleton_method(name, &block)
extend Module.new{define_method name, &block}
end
end
f = Foo.new
f.define_singleton_method(:hoge) do |arg|
puts arg
end
f.hoge('aaaaaaa')
# 特異メソッドを定義するメソッド
# see also: http://d.hatena.ne.jp/h-hirai/20080627/1214536733
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment