[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: newbie question about attr_reader

dblack

11/16/2006 12:01:00 PM

2 Answers

Xavier Noria

11/17/2006 9:48:00 AM

0

On Nov 16, 2006, at 1:01 PM, dblack@wobblini.net wrote:

> class C
> class << self
> attr_accessor :x
> end
> end
>
> Now, the class object C has an attribute "x":
>
> C.x = 1
> puts C.new.class.x # 1

David, technically is there any relationship between the attribute @x
here

class A
@x = 1
end

and the @x that accessor deals with? That would be an attribute of
what? Is there a singleton instance of the singleton class? Or is
that @x an attribute of A as instance of Class? I tried to get this
right with examples but I guess the exact answer comes from the
actual implementation.

-- fxn

fxn@feynman:~/tmp$ cat foo.rb
class A
@x = 0
@y = 1
class << self
def x
@x
end
attr_accessor :y
end
end

puts A.x, A.y
fxn@feynman:~/tmp$ ruby foo.rb
0
1


dblack

11/17/2006 11:09:00 AM

0