A
Artur Merke
Hi
class A
attr_accessor :a
end
a= A.new
b= A.new
#this adds a new attribute to the object 'b'
def b.dummy
@dummy
end
def b.dummy=(val)
@dummy= val
end
b.dummy= "hello world"
print "\n", b.dummy
Is there a shorthand notation for adding attributes to an object?
For example one could think of the equivalent of adding an attribute to a
class, like
b.attr_accessordummy) #illegal in ruby
Of course I could define a sort of public 'attr_accessor' for the class
'A' by myself, but I do NOT want to change/extend the class, only some objects.
any suggestions?
Artur
class A
attr_accessor :a
end
a= A.new
b= A.new
#this adds a new attribute to the object 'b'
def b.dummy
@dummy
end
def b.dummy=(val)
@dummy= val
end
b.dummy= "hello world"
print "\n", b.dummy
Is there a shorthand notation for adding attributes to an object?
For example one could think of the equivalent of adding an attribute to a
class, like
b.attr_accessordummy) #illegal in ruby
Of course I could define a sort of public 'attr_accessor' for the class
'A' by myself, but I do NOT want to change/extend the class, only some objects.
any suggestions?
Artur