Module: Attrio::Helpers

Extended by:
Helpers
Included in:
Helpers
Defined in:
lib/attrio/helpers.rb

Instance Method Summary collapse

Instance Method Details

#symbolize_hash_keys(hash) ⇒ Object

note that returning hash without symbolizing anything does not cause this to fail



17
18
19
20
21
22
23
# File 'lib/attrio/helpers.rb', line 17

def symbolize_hash_keys(hash)
  hash.inject({}) do |new_hash, (key, value)|
    new_hash[(key.to_sym rescue key) || key] = value
    new_hash
  end
  hash
end

#to_a(object) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/attrio/helpers.rb', line 5

def to_a(object)
  if object.nil?
    []
  elsif object.respond_to?(:to_ary)
    object.to_ary || [object]
  else
    [object]
  end
end