Module: WithOrder::HashExtraction

Included in:
ActionViewExtension
Defined in:
lib/with_order/hash_extraction.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) extract_hash_value(hash, key)



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/with_order/hash_extraction.rb', line 3

def extract_hash_value(hash, key)
  return hash[key] if key.is_a?(Symbol)

  first_key, remaining_content = key.to_s.match(/^([^\[]+)(.*)$/).captures

  if remaining_content == ''
    hash[first_key]
  else
    eval "hash[first_key.to_sym]#{remaining_content} rescue nil"
  end
end