
Subject: [ruby-talk:444061] A simple question about arguments Date: Sat 17 Dec 22 06:34:17AM +0000 Quoting Henry R via ruby-talk (ruby-talk@ml.ruby-lang.org):
Sorry for this newbie question. For arguments to ruby methods, what's difference between these two?
method(x:y) method(x=>y)
x:y is a shorthand for :x=>y. That is: a hash with one element, that has as key *symbol* :x, and as value whatever is in variable y. In the second case, the key of the hash is whatever you have currently in variable x. If you have this short script: --8<----8<----8<----8<-- def m(h) pp h pp h.class pp h.keys[0] pp h.keys[0].class end x=1 y=2 m(x=>y) print("\n") m(x:y) --8<----8<----8<----8<-- and run it, you obtain {1=>2} Hash 1 Integer {:x=>2} Hash :x Symbol HTH Carlo -- * Se la Strada e la sua Virtu' non fossero state messe da parte, * K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)