svg - Ruby's named parameters with hyphens -


i have generate svg files, , doing ruby's nokogiri. nice thing nokogiri lets create attributes passing hash "functions", so

doc.rect(:x => 0, :y => 0, :width => 100, :height => 100) 

which great. there attributes have hyphens: in case can take advantage of ruby's awesomeness , like

doc.rect(:x => 0, :y => 0, :width => 100, :height => 100, :stroke => 'black', 'stroke-width' => 3) 

and relatively well. enter ruby 2.0 , named parameters. prefer syntax, it's bit more concise , bit more smalltalkesque, like. however, way create hyphenated attributes mix 2 approaches, provided place 'hash' after named parameters (i assume has way, haven't checked). in case, it's ugly.

is there way wise people can conjure create hyphenated attributes using named parameters syntax?

edit: clarify, named parameters this:

doc.rect(x: 0, y: 0, width: 100, height: 100) 

use either

'stroke-width'.to_sym 

or

:'stroke-width' 

both evaluate symbol. actually, since named parameters derived syntax new ruby2 hash notation, still may mix both like:

params = { named: 'param1', :'old-style' => 'param2' }  

and, hence:

doc.rect x: 0, y: 0, :'stroke-width' => 3 

it’s syntax sugar only, inside well-known old hash. btw, there no way omit hash-rockets keys, containing \ws.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -