[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ruby 1.8 strange behavior

Dmitry V. Sabanin

9/11/2003 5:15:00 PM

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 :)

--
sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.


2 Answers

ts

9/11/2003 5:19:00 PM

0

>>>>> "D" == Dmitry V Sabanin <sdmitry@lrn.ru> writes:

D> Both ruby1.6 and ruby1.7 puts "my_own_return_value", but ruby1.8 puts
D> "big". I''m interested if this is right.

The modification is intentional.


Guy Decoux




Mauricio Fernández

9/11/2003 8:35:00 PM

0

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