is this a feature or a bug?

Discussion in 'Ruby' started by Rie!, Mar 11, 2008.

  1. Rie!

    Rie! Guest

    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

    m:~ arie$ irb
    ?> h[:b] = 2
    => [1, 2]=> {:a=>[1, 2], :b=>2}
    Rie!, Mar 11, 2008
    1. Advertisements

  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.
    John Barnette, Mar 11, 2008
    1. Advertisements

  3. Rie!

    Todd Benson Guest

    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 Benson, Mar 11, 2008
  4. Rie!

    rofiq Guest

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

    rofiq, Mar 11, 2008
  5. Rie!

    Arlen Cuss Guest

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

    "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 Cuss, Mar 11, 2008
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.