Method: DeepStruct::HashWrapper#indiffrently
- Defined in:
- lib/deepstruct.rb
#indiffrently(key, &block) ⇒ Object
Given a symbol or a string this yields the variant of the key that exists in the wrapped hash if any. If none exists (or the key is not a symbol or string) the input value is passed through unscathed.
38 39 40 41 42 43 |
# File 'lib/deepstruct.rb', line 38 def indiffrently(key, &block) return yield(key) if @value.has_key?(key) return yield(key.to_s) if key.is_a?(Symbol) && @value.has_key?(key.to_s) return yield(key.to_sym) if key.is_a?(String) && @value.has_key?(key.to_sym) return yield(key) end |