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



376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/nice/hash/add_to_ruby.rb', line 376

def deep_symbolize_keys
  if is_a? Hash
    return reduce({}) do |memo, (k, v)|
             memo.tap { |m| m[k.to_s.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



394
395
396
# File 'lib/nice/hash/add_to_ruby.rb', line 394

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