Skip to content

Instantly share code, notes, and snippets.

@manveru
Created February 10, 2012 21:41
Show Gist options
  • Save manveru/1793151 to your computer and use it in GitHub Desktop.
Save manveru/1793151 to your computer and use it in GitHub Desktop.
class Hash
def true_of?(key, &block)
TrueOf.new(self, key).instance_eval(&block)
end
end
class TrueOf
attr_reader :key, :value
def initialize(hash, key, &block)
@hash = hash
@key = key
@value = @hash[key]
end
end
h = {a: 1}
p h.true_of?(:a){ key == :a && value == 1 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment