class MaybeHash

Constants

VERSION

Attributes

value[R]

Public Class Methods

new(value) click to toggle source
# File lib/maybe_hash.rb, line 7
def initialize(value)
  @value = value
end

Public Instance Methods

method_missing(attribute) click to toggle source
# File lib/maybe_hash.rb, line 11
def method_missing(attribute)
  self.class.new(choose_value(attribute))
end

Private Instance Methods

choose_value(attribute) click to toggle source
# File lib/maybe_hash.rb, line 17
def choose_value(attribute)
  if respond_to_methods?(:[], :keys, :values)
    @value[attribute]
  elsif @value.respond_to?(attribute)
    @value.send(attribute)
  else
    nil
  end
end
respond_to_methods?(*list) click to toggle source
# File lib/maybe_hash.rb, line 27
def respond_to_methods?(*list)
  list.all? do |name|
    @value.respond_to?(name)
  end
end