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
    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.com/2bjgvn,
    ruby: http://www.ruby-lang.org/id/about/ }
    Rie!, Mar 11, 2008
    #1
    1. Advertising

  2. On Mon, Mar 10, 2008 at 10:59 PM, Rie! <> 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.
    John Barnette, Mar 11, 2008
    #2
    1. Advertising

  3. Rie!

    Todd Benson Guest

    On Tue, Mar 11, 2008 at 12:59 AM, Rie! <> 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
    Todd Benson, Mar 11, 2008
    #3
  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 :)

    On Tue, Mar 11, 2008 at 12:59 PM, Rie! <> 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.com/2bjgvn,
    > ruby: http://www.ruby-lang.org/id/about/ }
    >
    >
    rofiq, Mar 11, 2008
    #4
  5. Rie!

    Arlen Cuss Guest

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

    On Tue, Mar 11, 2008 at 8:15 PM, S2 <> 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
    Arlen Cuss, Mar 11, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shel Blauman [MSFT]

    Re: feature or bug?

    Shel Blauman [MSFT], Aug 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    385
    Shel Blauman [MSFT]
    Aug 11, 2003
  2. Replies:
    14
    Views:
    1,456
  3. Replies:
    6
    Views:
    1,919
  4. Meelis Lilbok

    Bug or Feature ;)

    Meelis Lilbok, Mar 30, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    410
    Juan T. Llibre
    Mar 30, 2006
  5. robic0
    Replies:
    7
    Views:
    100
    Samwyse
    Jan 24, 2006
Loading...

Share This Page