Ask a Question related to Ruby, Design and Development.
-
T. Onoma #1
Re: Again, Rite explanation needed (keyword args and new hash syntax)
> Hi gurus and nubys,
whos the bigger bother? :) and i wouldn't think you could be rude. (well, maybe if you REALLY tried)>
> Again here to bother you :)
its an obvious refection of the new hash syntax. in essence he's saying:> I wonder:
> why we introduce the ':' syntax ?
def f(a,:b=>2,**kwd) # == def f(a,b:2,**kwd)
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!> 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?
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)
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."> PS
> btw the 'a: c' syntax for hash is really cool.
>
> I always hate to type 'a'=>b or :a=>b.
in what way?> Nobody expects a string literal or a regexp literal to work like the
> rest of the code.
yes, it cetainly does.> But we expect this from Arrays and Hashes (and somewy Ranges).
> This must mean something.
i'll drink to that.> Possibly that I need more coffe in the morning.
thanks for the bother,
-t0
T. Onoma Guest
-
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... -
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... -
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 = {... -
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... -
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...... -
gabriele renzi #2
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::
well, if you write>>> Nobody expects a string literal or a regexp literal to work like the
>> rest of the code.
>in what way?
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



Reply With Quote

