![]() | define_method in instance_eval |
|
18 Jun 2008, 23:17
James Whiteman (4 posts) |
Hello, all. Does anyone have a good explanation for this?
It seems that define_method is pushing the method ‘shout’ into Foo’s own m_tbl instead of in the metaclass. |
|
19 Jun 2008, 12:53
Dave Thomas (231 posts) |
define_method always creates an instance method—now idea why, but it’s a deliberate decision of the implementers. Dave |
|
19 Jun 2008, 16:09
James Whiteman (4 posts) |
Thanks, Dave—fantastic series by the way. |
|
26 Dec 2008, 14:56
khaled alhabache (1 post) |
You can bypass that by defining the method to your singleton class class Object
end class Foo Foo.singleton_class.class_eval do
define_method(:shout) do
“shouting…”
end puts Foo.respond_to? :shout #true |
| You must be logged in to comment |

