Hello,

I'm going through a book which presents an example from which I'm a bit
confused over.

Here's the example;

----------

class Person
  def initialize(name)
    set_name(name)
  end

  def name
    @first_name + ' ' + @last_name
  end

  def set_name(name)
    first_name, last_name = name.split(/\s+/)
    set_first_name(first_name)
    set_last_name(last_name)
  end

  def set_first_name(name)
    @first_name = name
  end

  def set_last_name(name)
    @last_name = name
  end
end

--------

If the name paranthesis input was something like "Jack Smith", then;

"first_name, last_name = name.split(/\s+/)" = first_name = Jack,
last_name = Smith.

Now here's the confusion;

"set_first_name(first_name)" = I don't quite understand this part. I
understand it becomes set_first_name(Jack), but  then why is this;

"  def set_first_name(name)" instead of "  def
set_first_name(first_name)".

Is it basically putting the value of (first_name) into (name), so
set_first_name(name) = set_first_name(Jack)? If so, could someone
explain why it works like this?

Thanks.

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