Class: Dragonfly::HashWithCssStyleKeys

Inherits:
Hash show all
Defined in:
lib/dragonfly/hash_with_css_style_keys.rb

Overview

HashWithCssStyleKeys is solely for being able to access a hash which has css-style keys (e.g. 'font-size') with the underscore symbol version

Examples:

opts = {'font-size' => '23px', :color => 'white'}
opts = HashWithCssStyleKeys[opts]
opts[:font_size]   # ===> '23px'
opts[:color]       # ===> 'white'

Instance Method Summary (collapse)

Methods inherited from Hash

#to_dragonfly_unique_s

Instance Method Details

- (Object) [](key)



12
13
14
15
16
17
18
# File 'lib/dragonfly/hash_with_css_style_keys.rb', line 12

def [](key)
  super || (
    str_key = key.to_s
    css_key = str_key.gsub('_','-')
    super(str_key) || super(css_key) || super(css_key.to_sym)
  )
end