From: "Jesús Gabriel y Galán" Date: 2010-10-11T16:59:28+09:00 Subject: Re: how do i add an instance variable to a class in Ruby On Mon, Oct 11, 2010 at 9:20 AM, Amit Tomar wrote: > Thanks all for your response ,what am doing wrong is ,using > > def initialize1 >  @a=10 > > end > >  instead of initialize am using initialize1 but what if i have some > other function instead initialize ,then how could access this variable > @a??? In Ruby, instance variables are created the first time you assign them some value. It can be done in the initialize method or in any other method: class A def a=(value) @a = value end def a @a end end a = A.new a.a = 3 puts a.a Now, if you try to access it before setting it, you will get nil: a = A.new puts a.a Jesus.