is this a feature or a bug?

J

John Barnette

sorry if it's been discussed as i don't know what the search keyword
for this scenario. it actually came up from _mistype_ (notice the
comma).

m:~ arie$ irb
h = {} => {}
h[:a] = 1,
?> h[:b] = 2
=> [1, 2]=> {:a=>[1, 2], :b=>2}

This is expected behavior. You've assigned a two-element list to h[:a]

- the number 1
- an assignment expression yielding the number 2

Since assignment expressions return their rval, everything's happy and legal.

This one-line version behaves identically to what you've typed:

h[:a] = [1, h[:b] = 2]



~ j.
 
T

Todd Benson

sorry if it's been discussed as i don't know what the search keyword
for this scenario. it actually came up from _mistype_ (notice the
comma).

m:~ arie$ irb
h = {} => {}
h[:a] = 1,
?> h[:b] = 2
=> [1, 2]=> {:a=>[1, 2], :b=>2}

Feature, I think. Otherwise, you wouldn't be able to do things like...

a, b = b, a

The comma, it seems, assumes precedence from the right side.

Todd
 
R

rofiq

menarik, hmm banyak hal2 begini yg gw jg gak tau.

oot gmail keren jg, postingan ari yg cross posting replynya dari
ruby-talk ama id-ruby bisa jadi satu thread gini :)

sorry if it's been discussed as i don't know what the search keyword
for this scenario. it actually came up from _mistype_ (notice the
comma).

m:~ arie$ irb
h = {} => {}
h[:a] = 1,
?> h[:b] = 2
=> [1, 2]=> {:a=>[1, 2], :b=>2}
 
A

Arlen Cuss

[Note: parts of this message were removed to make it a legal post.]

this looks like rot13 :)
"zranevx, uzz onalnx uny2 ortvav lt tj wt tnx gnh.

bbg tznvy xrera wt, cbfgvatna nev lt pebff cbfgvat ercylaln qnev
ehol-gnyx nzn vq-ehol ovfn wnqv fngh guernq tvav :)"

Our normal methods are useless here!

Arlen
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top