Class: Object

Inherits:
BasicObject
Defined in:
lib/nice/hash/add_to_ruby.rb

Instance Method Summary collapse

Instance Method Details

#deep_symbolize_keysObject

symbolize hash of arrays and array of hashes Taken from gist https://gist.github.com/Integralist/9503099 Thanks to @integralist



302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/nice/hash/add_to_ruby.rb', line 302

def deep_symbolize_keys
  if is_a? Hash
    return reduce({}) do |memo, (k, v)|
             memo.tap { |m| m[k.to_sym] = v.deep_symbolize_keys }
           end
  end

  if is_a? Array
    return each_with_object([]) do |v, memo|
             memo << v.deep_symbolize_keys
           end
  end
  self
end

#in?(array) ⇒ Boolean

include? but the opposite. Check if the object is included on the array

Returns:



320
321
322
# File 'lib/nice/hash/add_to_ruby.rb', line 320

def in?(array)
    array.include?(self)
end