From: Josh Cheek Date: 2012-02-13T00:13:52+09:00 Subject: Re: the ruby syntax --f46d043be25ee4502604b8c5cd6d Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sun, Feb 12, 2012 at 7:49 AM, maven apache wrote= : > 2012/2/12 Bartosz Dziewo=C5=84ski > > > When a hash is the last argument to a method, you can skip its open- > > and close-braces. > > > > So this: > > IO.new("data.txt", mode: 'w:UTF-16LE', cr_newline: true) > > Is the same as this: > > IO.new("data.txt", {mode: 'w:UTF-16LE', cr_newline: true}) > > > > But in the ruby document:http://www.ruby-doc.org/docs/ProgrammingRuby/ > > Definiation of a hash should like this: > > {'key'=3D>'value'.....} > > Now in the IO.new exmaple,it is written as {key:value}. Is the ':' symbo= l > same as '=3D>'?? I do not find it is methioned in any document. > > So, again, you could figure out the answer to this by writing a method that simply prints the inspection of its args. Try this: def meth(arg) p arg end meth {:a =3D> 'b'} # ~> -:5: syntax error, unexpected tASSOC, expecting '}' # ~> ...9178_68393_18610 =3D (meth {:a =3D> 'b'});$stderr.puts("!XMP1329... # ~> ... ^ # hmm, that's strange, what if I do this? meth({:a =3D> 'b'}) # >> {:a=3D>"b"} # well that worked, I wonder why (contemplate it for later, or ask if you can't figure it out) # now what about those curly braces? meth(:a =3D> 'b') # >> {:a=3D>"b"} # okay, I guess they are the same. # now I was thinking that the ':' symbol is same as '=3D>', lets see meth(a: 'b') # >> {:a=3D>"b"} # aah, apparently it is... but wait, what if I have a number for a key? meth(1: 'b') # ~> -:5: syntax error, unexpected ':', expecting ')' # ~> meth(1: 'b') # ~> ^ # ~> -:5: syntax error, unexpected ')', expecting $end # Hmm, maybe it only works for symbol arguments # ... etc ... --f46d043be25ee4502604b8c5cd6d--