ruby 1.8 strange behavior

D

Dmitry V. Sabanin

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

ts

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
 
M

Mauricio Fernández

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.
-- (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,125
Messages
2,570,748
Members
47,302
Latest member
MitziWragg

Latest Threads

Top