On 17 May 2011, at 02:20, John Merlino <li...@ruby-forum.com> wrote: > THe guy says: > "The first instance_eval is used to add class method has_attribute into > Object so that we can call it in all the inherited class." > > I'm a little thrown off by this statement. First, Object itself is an > instance of class Class. Someone here even said before "Object is an > instance of Class". So "class Object end "implies that Object is an > instance of class, equivalent to: Object = Class.new. Hence, we can > invoke instance_eval on Object, since Object is an instance. What > confuses me here is has_attribute appears to be an instance method (e.g. > def a end) not class method (e.g. def self.a end). So why does guy say > we add class method has_attribute? > Well a class method called has_attribute has been added. I think this is just awkward phrasing - instance_eval is indeed invoked on Object. As to why that results in a class method, that's sort of what instance_eval does - there are lots of articles on instance_eval and class_eval etc. that go into the details
Fred. > In fact, the difference between Object class and Class class is that > when you add methods to class Class, those methods become available to > any class that is created as well (since all classes created using class > construct inherit from Class) and you can use those methods within any > class. However, that's not what we do above. We extend Object above. > When you instantiate a class, you inherently create an object instance, > so that object instance should have available the methods defined in > Object. So then how can we access that method within a class, such as > that being done in class A above? > > Thanks for response > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.