Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/hoshi/monkey_patches.rb
Overview
TODO: When 1.9 goes away, monkey-patching should be changed to refinements. See: blog.headius.com/2012/11/refining-ruby.html
Instance Method Summary collapse
-
#to_html_options(double_quotes = true) ⇒ Object
Makes this hash fit to be put into a tag.
Instance Method Details
#to_html_options(double_quotes = true) ⇒ Object
Makes this hash fit to be put into a tag. 1, b: “two”, c: true.to_html_options # => ‘a=“one” b=“two” c’
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/hoshi/monkey_patches.rb', line 7 def double_quotes = true qchar = double_quotes ? '"' : "'" map { |k,v| if v == true # Intentional. k.to_s else "#{k}=#{qchar}#{v.to_s.gsub(qchar, CGI.escapeHTML(qchar))}#{qchar}" end }.join(' ') end |