[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Subject: What *exactly* does an instance variable in the

Arno J.

8/16/2007 3:43:00 PM

Any instance variable refers to the object currently being self at the
moment.

> @tl_instance = "hello ruby"

self here is "main", which is the top level default object

> puts @tl_instance
>
> def tl_method
> puts "from tl_method -- @tl_instance: #{@tl_instance}"
> end

self here is "main" too

>
> tl_method
>

=> Working as expected

> class Tl_class
> def tlc_method
> puts "from tlc_method -- @tl_instance: #{@tl_instance}"
> end
> end
>
> Tl_class.new.tlc_method
> ------------

Inside tlc.method, self is the "Tl_class.new" object, which doesn't know
about any @tl_instance.
--
Posted via http://www.ruby-....