Again, Rite explanation needed (keyword args and new hash syntax)

Ask a Question related to Ruby, Design and Development.

  1. #1

    Default Re: Again, Rite explanation needed (keyword args and new hash syntax)

    > Hi gurus and nubys,
    >
    > Again here to bother you :)
    whos the bigger bother? :) and i wouldn't think you could be rude. (well, maybe if you REALLY tried)
    > I wonder:
    > why we introduce the ':' syntax ?
    its an obvious refection of the new hash syntax. in essence he's saying:

    def f(a,:b=>2,**kwd) # == def f(a,b:2,**kwd)
    > Why can't we call a kwd arg like
    > f(1,b=5)
    >
    > I suppose this is to avoid conflicts with normal assignment..
    > but what's wrong with making go away the assignment in method calling?
    i dobt that should go away, but to be honest, i am stumped on the sytax too. when i first saw it i thought "why more syntax" the parameters already have names. we only need a way to specify them in the method call, not in the def!

    that's were your = doesn't work. you can make an assignment in a method invocation. that's just common place. (perhaps not used a lot, but enough) but adding => or : sugar to calls causes a conflict with the way in which ruby currently handles hash parameters. so somethings got to give, in order to do:

    f(1,:b=>5)
    > PS
    > btw the 'a: c' syntax for hash is really cool.
    >
    > I always hate to type 'a'=>b or :a=>b.
    got a feeling symbols are going to get a lot more use if this happens. not sure how i feel about it. its certainly not bad, but it means even more syntax to understand. "hey nuby, a:4 and :a=>4 mean the same thing."
    > Nobody expects a string literal or a regexp literal to work like the
    > rest of the code.
    in what way?
    > But we expect this from Arrays and Hashes (and somewy Ranges).
    > This must mean something.
    yes, it cetainly does.
    > Possibly that I need more coffe in the morning.
    i'll drink to that.

    thanks for the bother,
    -t0

    T. Onoma Guest

  2. Similar Questions and Discussions

    1. AI Files Linked into ID 2.0 – Drop Shadows – Explanation Needed please
      Something occurred today that I need an explanation for: I am using InDesign 2.0.2 to compile a document that is full of Illustrator files linked...
    2. Again, Rite explanation needed (keyword args and new hash syntax)
      Hi gurus and nubys, Again here to bother you :) Please note that I'm not here to start a flame. I actually want to understand matz' and...
    3. Sort a hash based on values in the hash stored as arrays of hashes
      Hmm. I'm not quite sure if I got the subject right, but I'll try to explain. :-) I've got a hash of elements stored like this: $VAR1 = {...
    4. hello world (asp.net) problem (syntax error) help needed :(
      Hi folks...I've just installed asp.net framework and asp.net sdk and I've cut and pasted a file from the web to test that it works. The problem...
    5. Another reference question (hash of hash references)
      beginners, I am trying to build a hash of hash references. My problem is that I need to be able to add a key/value pair to the internal hashes......
  3. #2

    Default Re: Again, Rite explanation needed (keyword args and new hash syntax)

    il Tue, 18 Nov 2003 19:14:50 +0900, "T. Onoma" <transami@runbox.com>
    ha scritto::




    >> Nobody expects a string literal or a regexp literal to work like the
    >> rest of the code.
    >
    >in what way?
    well, if you write
    a=10
    b='a'

    you expect b to be 97.chr.

    If you write b=/a/ you know it is someway translated in a pattern.
    But if you write
    b=[a]
    or b={a=>4}

    you expect 'ciao' in the Array or Hash. For sure this is not wrong..
    just interesting :)

    gabriele renzi Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139