Explanation required on def method = (.)

hello, i’ve come across a code like

def password=(pass)
@password = pass
.
.
end

Anyone can please explain to me what is happening in the first line
itself for the def part? the code I saw did not provide anything on it

On 27 June 2012 19:54, Ritesh T. [email protected] wrote:

hello, i’ve come across a code like

def password=(pass)
@password = pass
.
.
end

Anyone can please explain to me what is happening in the first line
itself for the def part? the code I saw did not provide anything on it

It is setting the instance variable @password to the parameter ‘pass’
that is passed in to the method. I suggest running through some basic
Ruby tutorials.

If you meant what is the line starting with def doing, then you still
need to look at the tutorials.

Colin

thanks Colin, I’ve started with the rails tutorials but it was the
password=(pass) which confused me somehow

On 27 June 2012 20:35, Ritesh T. [email protected] wrote:

thanks Colin, I’ve started with the rails tutorials but it was the
password=(pass) which confused me somehow

Have a look at http://www.rubyist.net/~slagell/ruby/accessors.html

Colin

please try http://ruby.railstutorial.org

在 2012年6月27日星期三UTC-7下午12时50分52秒,Ruby-Forum.com User写道:

thanks for the link, i’ve bought some RoR books to get further info, but
if you have some websites with some easy to use examples for a beginner
am most welcome to accept them :slight_smile: