Mauricio Fernández
9/11/2003 8:35:00 PM
On Fri, Sep 12, 2003 at 02:14:36AM +0900, Dmitry V. Sabanin wrote:
> Hi,
> I''ve started making my own C extension to ruby, and found that strange
> behavior:
> class MyTest
> def []=(key,val)
> "my_own_return_value"
> end
> end
> test = MyTest.new
> p test[1] = "big"
>
> Both ruby1.6 and ruby1.7 puts "my_own_return_value", but ruby1.8 puts
> "big". I''m interested if this is right.
> I know that it''s kinda stupid to do something like this and I found that just
> by accident, but anyway :)
The rationale for that is making it work like an assignment:
a = b[0] = 1
# here you expect a == 1, not a = return value of []=
Same thing for
a = b.bla = 1
--
_ _
| |__ __ _| |_ ___ _ __ ___ __ _ _ __
| ''_ \ / _` | __/ __| ''_ ` _ \ / _` | ''_ \
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com
MSDOS didn''t get as bad as it is overnight -- it took over ten years
of careful development.
-- dmeggins@aix1.uottawa.ca