Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the proper hash syntax in Ruby 2.0? [closed]

Tags:

ruby

Should I use ?

{ :first_name => "Mathieu", :last_name => "Jackson" }

or

{ first_name: "Mathieu", last_name: "Jackson" } 
like image 974
Mathieu Avatar asked May 01 '13 13:05

Mathieu


1 Answers

There is no difference between the two, so it is personal preference. Though I would expect most people writing new code for 2.0 will use the second format.

It's important to note that if you are developing for open-source / public consumption and want a wide user base you should use the "old" style of hashes. Ruby 1.8.x, as well as JRuby and other ruby implementations apart from RMI, does not support the terse syntax.

like image 53
Dan Reedy Avatar answered Oct 14 '22 12:10

Dan Reedy