Is this a feature or a bug?

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]

h
=> {:a=>[1, 2], :b=>2}

On Mon, Mar 10, 2008 at 10:59 PM, Rie! [email protected]
wrote:

h
=> {: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.

On Tue, Mar 11, 2008 at 12:59 AM, Rie! [email protected]
wrote:

h
=> {: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

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

rofiq wrote:

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

this looks like rot13 :slight_smile:

On Tue, Mar 11, 2008 at 8:15 PM, S2 [email protected] wrote:

rofiq wrote:

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

this looks like rot13 :slight_smile:

"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