From: Josh Cheek Date: 2010-07-26T06:11:40+09:00 Subject: Re: syntax --0016e65ae044b4e2cd048c3cb631 Content-Type: text/plain; charset=ISO-8859-1 On Sun, Jul 25, 2010 at 7:41 AM, Raghu Maddali wrote: > I apologize for miscommunication.I know that Ruby will not have any > pointers and I guess its a variable declared with private access > modifier.Its like > > private $config; > $this->config = parse_ini_file('conf/Voyager.ini', true); > > So,how would you code this in Ruby?Is that the same > > private $config > $self.config=parse_ini_file(....)??? > > Raghu > > > presumably you want self.config = parse_ini_file(...) your actual > > question > > is a little unclear (I assume you meant to refer to a different > > language) > > but you should note that there are no pointers in Ruby, and in the > > preceeding example, "config=" is a method defined on self, you are not > > directly setting an instance variable like you would be in Java, but > > rather > > invoking a method which probably sets an instance variable, though not > > necessarily. > > -- > Posted via http://www.ruby-forum.com/. > > In Ruiby, all instance variables are private (hence the need to use the #config= method) From within an object, you can access its private instance variables directly by suing the @ sigil @config = parse_ini_file(...) from outside the object, you must use a method. class Person def name=(newname) @name = newname end def name @name end end person = Person.new # invoke the #name= method, which will set @name person.name = 'Josh' # invoke the #name method, which will get @name person.name # => "Josh" --0016e65ae044b4e2cd048c3cb631--