Look into define_method, class_eval and instance_eval. It will be one
of those or higher ordered scoped where singleton_ is before them. Of
course you can always user eval primitive or monkey patch it all the
same.
~Stu
···
On Fri, May 17, 2013 at 2:42 PM, Love U Ruby <lists@ruby-forum.com> wrote:
class Foo
def suprim;end
end
p foo = Foo.new #=> #<Foo:0x90bd908>
p foo.method(:suprim) #=> #<Method: Foo#suprim>
p Bar=foo.singleton_class #=> #<Class:#<Foo:0x90bd908>>
p foo.define_singleton_method(:hello) { "#{self}: Hello there!" } #=>
#<Proc:0x90bd2a0@/home/kirti/ruby/test.rb:8 (lambda)>
p Bar.method(:hello) #=> `method': undefined method `hello' for class
`Class' (NameError)
My question is how to create a method object of an singleton method,like
I did `foo.method(:suprim)`?