Module: HasHelpers::CoreExt::Hash
- Defined in:
- lib/has_helpers/core_ext/hash.rb
Instance Method Summary collapse
- #camelize_keys ⇒ Object
-
#camelize_keys! ⇒ Object
Camelize the first level keys of a hash.
- #to_action ⇒ Object
- #to_html_attrs ⇒ Object
- #to_icon ⇒ Object
- #to_input ⇒ Object
- #to_renderable ⇒ Object
- #with_nested_access ⇒ Object
-
#with_nested_access! ⇒ Object
Allow any level of access by providing a default value at each level.
Instance Method Details
#camelize_keys ⇒ Object
44 45 46 |
# File 'lib/has_helpers/core_ext/hash.rb', line 44 def camelize_keys clone.camelize_keys! end |
#camelize_keys! ⇒ Object
Camelize the first level keys of a hash.
Example
h = Hash.new h = "Brendan"
h.camelize_keys! # => { firstName: "Brendan" }
35 36 37 38 39 40 41 42 |
# File 'lib/has_helpers/core_ext/hash.rb', line 35 def camelize_keys! keys.each do |key| camelized_key = key.to_s.camelize(:lower) camelized_key = camelized_key.to_sym if key.is_a? Symbol self[camelized_key] = self.delete(key) end self end |
#to_action ⇒ Object
48 49 50 |
# File 'lib/has_helpers/core_ext/hash.rb', line 48 def to_action ::Action.new(self) end |
#to_html_attrs ⇒ Object
60 61 62 |
# File 'lib/has_helpers/core_ext/hash.rb', line 60 def to_html_attrs ::HasHelpers::UIAttributes::HTMLAttributes::HTMLAttrs.new(self) end |
#to_icon ⇒ Object
52 53 54 |
# File 'lib/has_helpers/core_ext/hash.rb', line 52 def to_icon ::HasHelpers::Icon.new(self[:name], **self.except(:name)) end |
#to_input ⇒ Object
56 57 58 |
# File 'lib/has_helpers/core_ext/hash.rb', line 56 def to_input ::Input.new(self) end |
#to_renderable ⇒ Object
64 65 66 |
# File 'lib/has_helpers/core_ext/hash.rb', line 64 def to_renderable ::RenderObject.new(self) end |
#with_nested_access ⇒ Object
24 25 26 |
# File 'lib/has_helpers/core_ext/hash.rb', line 24 def with_nested_access clone.with_nested_access! end |
#with_nested_access! ⇒ Object
19 20 21 22 |
# File 'lib/has_helpers/core_ext/hash.rb', line 19 def with_nested_access! self.default_proc = -> h, key { h[key] = ::Hash.new(&h.default_proc) } self end |