Hi
Whats the differents between this three classes. Why the
my_attr_accesor dosent create getters and setter clases.
Thanks in advance
#----------------------------------------------------------------------
#----------------------------------------------------------------------
class Class
def my_attr_accessor( *args )
args.each do |name|
self.class.class_eval do
attr_accessor :"#{name}"
end
end
end
end
=> nil
class MyNewClass
my_attr_accessor :id, :diagram, :telegram
end
=> [:id, :diagram, :telegram]
class MyClass
attr_accessor :id, :diagram, :telegram
end
=> nil
class Another_class
def initialize
[“id”,“diagram”,“telegram”].each do |name|
self.class.class_eval do
attr_accessor :"#{name}"
end
end
end
end
=> nil
mnc = MyNewClass.new
=> #MyNewClass:0xb7b97d0c
mc = MyClass.new
=> #MyClass:0xb7b950fc
ac = Another_class.new
=> #<Another_class:0xb7b82358>
ac.diagram
=> nil
mc.diagram
–
Pedro Del G.
Email : [email protected]