Skip to content

Instantly share code, notes, and snippets.

@hashrocketeer
Created October 21, 2010 23:23
Show Gist options
  • Save hashrocketeer/639597 to your computer and use it in GitHub Desktop.
Save hashrocketeer/639597 to your computer and use it in GitHub Desktop.
class FuzzyHash
attr_reader :attrs
def initialize(attrs)
@attrs = attrs
end
def blank?
attrs.nil?
end
def nil?
attrs.nil?
end
def to_s
""
end
def [](key)
if blank?
return self
end
value = attrs[key]
case value
when Hash, HashWithIndifferentAccess
FuzzyHash.new(value.dup)
when nil
FuzzyHash.new(nil)
else
value
end
end
def method_missing(*args)
if blank?
self
else
self[args.first]
end
end
end
def fuzzy_attributes
FuzzyHash.new(attributes.dup)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment