[QA] better page object explanation, colon confusion
Dan Duvall
dduvall at wikimedia.org
Mon Oct 27 17:58:02 UTC 2014
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 `=>`).
e.g.
{ :foo => "x", :bar => "y" }
could/should be written as
{ foo: "x", bar: "y" }
whereas the following can't be written any other way.
{ "foo" => "x", "bar" => "y" }
{ ["foo", "bar"] => "x" }
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]
In other words...
foo(1, bar: "x")
...defined as the following in Ruby 1.9...
def foo(a, options = {})
...could be refactored to the following in Ruby 2.0.
def foo(a, bar: "default")
Anyway, that's probably more than you wanted to know, but I thought I'd
share what I could remember about the history. :)
[1]: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/13635
On Mon, Oct 27, 2014 at 8:48 AM, Željko Filipin <zfilipin at wikimedia.org>
wrote:
> On Sat, Oct 25, 2014 at 6:37 AM, S Page <spage at wikimedia.org> wrote:
>
>> E.g. https://github.com/cheezy/page-object/wiki/Elements has
>>
>> button(:your_name, :id => 'an_id')
>>
>> but our features/support/foo_page.rb files have e.g.
>>
>> h1(:first_heading, id: "firstHeading")
>>
>> is this Ruby strangeness, or just supporting alternative syntaxes?
>>
>
> `: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.
>
> More information:
>
> https://github.com/bbatsov/ruby-style-guide#no-mixed-hash-syntaces
>
> RuboCop is instructed to allow both, at the moment. Example for Flow:
>
>
> https://github.com/wikimedia/mediawiki-extensions-Flow/blob/master/.rubocop_todo.yml#L61-L65
>
> Željko
>
> _______________________________________________
> QA mailing list
> QA at lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/qa
>
>
--
Dan Duvall
Automation Engineer
Wikimedia Foundation <http://wikimediafoundation.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.wikimedia.org/pipermail/qa/attachments/20141027/fb918205/attachment.html>
More information about the QA
mailing list