Module: HotelsPro::Underscorer
- Included in:
- Response
- Defined in:
- lib/hotels_pro/underscorer.rb
Instance Method Summary collapse
-
#underscore(object) ⇒ Object
Detect nested hashes and underscore their keys.
Instance Method Details
#underscore(object) ⇒ Object
Detect nested hashes and underscore their keys
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hotels_pro/underscorer.rb', line 4 def underscore(object) case object when Hash object.inject({}) do |hash, (k, v)| hash[k.underscore] = underscore(v) hash end when Array object.inject([]) do |arr, element| arr << underscore(element) arr end else object end end |