I'm little confused about class variables
class Polygon
attr_accessor :sides
@@sides = 10
end
p Polygon.new.sides
I get nil as return from sides??
but when I do this
class Polygon
@@sides = 10
def sides
@@sides
end
end
This work, but then I need to write all the accessors for every global
variable?
Regards,
Jamal
--
Posted via http://www.ruby-forum.com/.
Well I don't want to write the set and get, I tought with attr_accessor
they write it for you?
Thanks Jason Roelofs :D
I actually just try it out, undefined method cattr_accesstor?
class Link
cattr_accessor :url, :response
def initialize(url)
@@url = URI::parse(url)
@@response = Net::HTTP.get(@@url)
end
end
link = Link.new("http://www.google.com/")
p link.response