From: Lorenzo Brito Morales Date: 2011-01-24T14:46:43+09:00 Subject: Re: class_eval Ok, thanks, in that way what actually we are doing is a class method not? a static called in java or csharp but the thing i really feel very weird is these class Class def add_accessor(accessor_name) self.class_eval %Q{ attr_accessor :#{accessor_name} } end end class Person end person = Person.new Person.add_accessor :name but why the method added to Class works on Person as class method ? if it is added in Class as instance method ? On Sun, Jan 23, 2011 at 11:29 PM, botp wrote: > On Mon, Jan 24, 2011 at 12:58 PM, Lorenzo Brito Morales > wrote: >>..., but i just want to the class Person was the only class whom have it. > > then just put it Person > > eg, > > class Person >  def self.add_accessor accessor_name >    self.class_eval %Q{ >    attr_accessor :#{accessor_name} >    } >  end > end > #=> nil > > person=Person.new > #=> # > > Person.add_accessor :name > #=> nil > > Person.add_accessor :gender > #=> nil > > person.name="Peter Cooper" > #=> "Peter Cooper" > > person.gender="male" > #=> "male" > > person.name > #=> "Peter Cooper" > > person.gender > #=> "male" > > best regards -botp > >