[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

is this a feature or a bug?

Arie Kusuma Atmaja

3/11/2008 6:00:00 AM

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}


--
r9 = { name: Rie!, ym: riyari3, skype: rubyninja,
blog: http://tinyurl....,
ruby: http://www.ruby-lang.org... }

5 Answers

John Barnette

3/11/2008 6:12:00 AM

0

On Mon, Mar 10, 2008 at 10:59 PM, Rie! <ariekusumaatmaja2@gmail.com> wrote:
> 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}

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.

Todd Benson

3/11/2008 6:18:00 AM

0

On Tue, Mar 11, 2008 at 12:59 AM, Rie! <ariekusumaatmaja2@gmail.com> wrote:
> 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}

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

rofiq

3/11/2008 7:19:00 AM

0

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

On Tue, Mar 11, 2008 at 12:59 PM, Rie! <ariekusumaatmaja2@gmail.com> wrote:
>
> 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}
>
>
> --
> r9 = { name: Rie!, ym: riyari3, skype: rubyninja,
> blog: http://tinyurl....,
> ruby: http://www.ruby-lang.org... }
>
>

S2

3/11/2008 9:13:00 AM

0

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

this looks like rot13 :)

Arlen Cuss

3/11/2008 9:54:00 AM

0

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

On Tue, Mar 11, 2008 at 8:15 PM, S2 <non.sto.gioando@nien.te> 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 :-)
>
> 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