<div dir="ltr">Zeljko pretty much summed it up. I would just add that the new syntax is limited to literal hashes with Symbol objects as keys. If you ever need to write a literal hash with keys of any other object type (e.g. String) you _must_ use the classic "rocket" style (using `=>`).<div><br></div><div>e.g.</div><div><br></div><div>  { :foo => "x", :bar => "y" }</div><div><br></div><div>could/should be written as</div><div><br></div><div>  { foo: "x", bar: "y" }</div><div><br></div><div>whereas the following can't be written any other way.</div><div><br></div><div>  { "foo" => "x", "bar" => "y" }</div><div>  { ["foo", "bar"] => "x" }</div><div><br></div><div>The main reason for the introduction of the new syntax, IIRC, is to make the transition to true keyword arguments in Ruby 2.1 easier. This is also the reason for leaving off the `{` and `}` of final hash arguments.[1]</div><div><br></div><div>In other words...</div><div><br></div><div>  foo(1, bar: "x")</div><div><br></div><div>...defined as the following in Ruby 1.9...</div><div><br></div><div>  def foo(a, options = {})</div><div><br></div><div>...could be refactored to the following in Ruby 2.0.</div><div><br></div><div>  def foo(a, bar: "default")</div><div><br></div><div>Anyway, that's probably more than you wanted to know, but I thought I'd share what I could remember about the history. :)</div><div><br></div><div>[1]: <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/13635">http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/13635</a></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 27, 2014 at 8:48 AM, Željko Filipin <span dir="ltr"><<a href="mailto:zfilipin@wikimedia.org" target="_blank">zfilipin@wikimedia.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><span class=""><div class="gmail_quote">On Sat, Oct 25, 2014 at 6:37 AM, S Page <span dir="ltr"><<a href="mailto:spage@wikimedia.org" target="_blank">spage@wikimedia.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>E.g. <a href="https://github.com/cheezy/page-object/wiki/Elements" target="_blank">https://github.com/cheezy/page-object/wiki/Elements</a> has <code><code></code></code><br><pre><code>  button(:your_name, :id => 'an_id')</code></pre>but our features/support/foo_page.rb files have e.g.<br><pre><code>  h1(:first_heading, id: "firstHeading")</code></pre>is this Ruby strangeness, or just supporting alternative syntaxes?</div></blockquote></div><br></span>`:id => 'an_id'` and `id: "firstHeading"` are Ruby hashes. The former is the Ruby 1.8 syntax (hash rocket), the latter is Ruby 1.9+ syntax.</div><div class="gmail_extra"><br></div><div class="gmail_extra">More information:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><a href="https://github.com/bbatsov/ruby-style-guide#no-mixed-hash-syntaces" target="_blank">https://github.com/bbatsov/ruby-style-guide#no-mixed-hash-syntaces</a><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">RuboCop is instructed to allow both, at the moment. Example for Flow:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><a href="https://github.com/wikimedia/mediawiki-extensions-Flow/blob/master/.rubocop_todo.yml#L61-L65" target="_blank">https://github.com/wikimedia/mediawiki-extensions-Flow/blob/master/.rubocop_todo.yml#L61-L65</a><span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div class="gmail_extra"><br></div><div class="gmail_extra">Željko</div></font></span></div>
<br>_______________________________________________<br>
QA mailing list<br>
<a href="mailto:QA@lists.wikimedia.org">QA@lists.wikimedia.org</a><br>
<a href="https://lists.wikimedia.org/mailman/listinfo/qa" target="_blank">https://lists.wikimedia.org/mailman/listinfo/qa</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Dan Duvall<div>Automation Engineer</div><div><a href="http://wikimediafoundation.org" target="_blank">Wikimedia Foundation</a><br></div></div>
</div>