![]() | class of an object with a singleton method ... |
|
15 Feb 2013, 13:51
Kedar Mhaswade (21 posts) |
On p356 (PDF, v5.0), on the section on Singletons, book introduces this snippet:
animal = "cat"
def animal.speak
puts "The #{self} says miaow"
end
and then on p357 it says:
But I find that animal.class is still String and not the anonymous class. How do I access the anon class that defines this method speak? |
|
27 Feb 2013, 15:38
Dave Thomas (233 posts) |
Ruby hides the singleton class from you when you ask an object for it’s class. But you can get it using animal.singleton_class |
| You must be logged in to comment |

