tenxian wrote:
> I even don't know what attr_accessor is.
class Dog
def initialize(a_name)
@name = a_name
end
def name #get the name
return @name
end
def name=(a_name) #set the name
@name = a_name
end
end
d = Dog.new("Spot")
puts d.name #Spot
d.name = "Red"
puts d.name #Red
======compare to: ============
class Dog
attr_accessor :name
def initialize(a_name)
@name = a_name
end
end
d = Dog.new("Spot")
puts d.name #Spot
d.name = "Red"
puts d.name #Red
--
Posted via http://www.ruby-forum.com/.