Re:R.I.P. Ruby Hash Rocket Syntax 1993-2010
by aaronbrethorst on Wednesday January 05, 2011 @10:23PM
(#2073771)
Combining Haml with jQuery Mobile makes it pretty much mandatory:
#main_page{:"data-role" => 'page'}
Re:R.I.P. Ruby Hash Rocket Syntax 1993-2010
by nex3 on Thursday January 06, 2011 @12:51AM
(#2074226)
Haml keys can be plain strings.
#main_page{"data-role" => 'page'}
`data-` attributes are also special-cased: #main_page{data: {role: 'page'}}
Re:R.I.P. Ruby Hash Rocket Syntax 1993-2010
by aaronbrethorst on Thursday January 06, 2011 @12:53AM
(#2074234)
I did not know that. Thanks for the heads up, and thanks for Haml and Sass!
Re:R.I.P. Ruby Hash Rocket Syntax 1993-2010
by snprbob86 on Thursday January 06, 2011 @06:43AM
(#2074939)
You can also use "HTML-style attributes" [1]
#main_page(data-role='page')
[1] http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#ht...
Re:R.I.P. Ruby Hash Rocket Syntax 1993-2010
by ericb on Wednesday January 05, 2011 @10:29PM
(#2073792)
> That said, for almost all use cases hashes use symbols as keys
I'd say there are more vanilla symbol hash uses by number, but the most interesting and powerful things you can do with hashes don't involve symbols for keys, imho.
The new syntax works only with conventional symbols (no quotes), not with any other key type, so no integers, strings, objects etc. For everything else, you can fall back to the original syntax. You can even mix then if you really feel the need (yech!)
That said, for almost all use cases hashes use symbols as keys, and for these cases the new syntax is much cleaner and I'm glad to see it