From: 7stud -- Date: 2008-03-26T15:22:50+09:00 Subject: Re: class_eval vs (class << object) Ruby Freak wrote: > What is the difference between class_eval and "class << object"? > > It seems like they are the same. I am thinking that class_eval affects > the greater class and "class_object" is used on a singleton class. Are > they mutually exclusive? > > Thanks class Dog attr_accessor :age def initialize(a) @age = a end end Dog.class_eval{ def show puts @age end } d1 = Dog.new(5) d2 = Dog.new(2) d1.show #5 d2.show #2 class Dog attr_accessor :age def initialize(a) @age = a end end d1 = Dog.new(5) class << d1 def show puts age end end d1.show #5 d2 = Dog.new(2) d2.show --output:-- undefined method `show' for # (NoMethodError) -- Posted via http://www.ruby-forum.com/.