is it possible to convert from a ruby object to Ruby class...
and, how to find the included classes in ruby program....
any idea.....
| SitePoint Sponsor |
is it possible to convert from a ruby object to Ruby class...
and, how to find the included classes in ruby program....
any idea.....




What does it mean to convert an object to a class?is it possible to convert from a ruby object to Ruby class...
and, how to find the included classes in ruby program....Code ruby:ObjectSpace.each_object(Class) do |c| puts c end








Have you tried the code you've entered as being what you'd like to happen? I ask because I think it will do just that:
This line will return "Dog".Code:puts d.class
Have a look at this description of the methods of the class Object:
http://whytheluckystiff.net/ruby/pic...l#Object.class
All classes have Object as a parent and therefore will have the same methods.





Yes.Have you tried the code you've entered as being what you'd like to happen?
What does 'it' refer to? What does 'that' refer to?I ask because I think it will do just that:
Hmm...maybe that's why I put "Dog" as a comment on that line.This line will return "Dog".
My tests are unable to confirm that statement:All classes have Object as a parent and therefore will have the same methods.
Based on the error message, it does not appear that all classes have the same methods.Code Ruby:class Dog def bark puts "Bow wow." end end class Cat end d = Dog.new d.bark c = Cat c.bark --output:-- Bow wow. r1test.rb:14: undefined method `bark' for Cat:Class (NoMethodError)




I think he means that all objects support the methods listed on the page he links to.
Bookmarks