Krekna, your understanding is correct:
#
>> x = Object.new
=> #<Object:0x24870738>
>> x.aa  = 10
NoMethodError: undefined method `aa=' for #<Object:0x24870738>
#
note method name reported: 'aa='

Sergey

----- Original Message ----- 
From: "Krekna Mektek" <krekna / gmail.com>
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
Sent: Thursday, May 11, 2006 5:12 AM
Subject: Writable attributes - how does this work?


Hi!

How does this actually work?

from the Pick Axe book:

irb>
1>  class Song
2 >  def duration=(new_duration)
3>     @duration = new_duration
4>   end
5> end
6>
7> song = Song.new("Bicylops", "Fleck", 260)
8> song.duration --> 260
9> song.duration = 257
10> song.duration --> 257

If a method name which is used to set the attribute is called
"duration=", how come that one can use song.duration = 257?

I mean, does it just work lik this, because the Ruby engine recognizes
the 'set attribute' method just because of the = sign after the
"duration" on line number two?

Tnx,
Krekna