From: Stu Date: 2013-04-27T08:33:20+09:00 Subject: Re: BEGINNER -CLASS QUERY --001a11c329e89dbbe604db4bf5a6 Content-Type: text/plain; charset=ISO-8859-1 It's a data type based on syntax sugar. "string".class is also: String.new( 'string').class [1,2].class is also: Array.new( [1,2]) Ruby provides a function macro to create getters and setters to your instance variables called attr_accessor . attr_accessor :foo dynamically creates two methods def foo; @foo; end def foo=( var); @foo=var; end The first is a getter and the second is a setter where the = token is sugar and can be used as so on an instance called say baz: baz.foo # returns @foo baz.foo = 42 # sets @foo to 42 The setter can be witten as so to expose the sugar: baz.foo=( 42) baz.foo=( 'bar') Hope that helps. On Mon, Apr 22, 2013 at 8:45 AM, shaik farooq wrote: > HEY as we know that the object conatins the instance variables that are > defined in the class > > > but in ruby we are not defining any data member in the class but object > of that class contains the instance variables > > can u please explain these > > -- > Posted via http://www.ruby-forum.com/. > > --001a11c329e89dbbe604db4bf5a6 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
It's a data type based on syntax sugar.

"string".class

is also:

String.new(= 'string').class

[1,2].class

is also:

Array.new( [= 1,2])

Ruby provides a function macro to create getters and set= ters to your instance variables called attr_accessor .

attr_ac= cessor :foo

dynamically creates two methods

def foo; @foo; end
def foo=3D( var); @foo=3Dvar; end

The first is a gette= r and the second is a setter where the =3D token is sugar and can be used a= s so on an instance called say baz:

baz.foo # returns @foo
baz.foo =3D 42 # sets @foo to 42<= br>
The setter can be witten as so to expose the sugar:
baz.fo= o=3D( 42)
baz.foo= =3D( 'bar')

Hope that helps.


On Mon, Apr 22, 2013 at 8:45 AM, shaik farooq <list= s@ruby-forum.com> wrote:
HEY as we know that the object conatins the = instance variables that are
defined in the class


but in ruby we are not defining any data member in the class but object
of that class contains the instance variables

can u please explain these

--
Posted via http://= www.ruby-forum.com/.


--001a11c329e89dbbe604db4bf5a6--