Skip to content

Instantly share code, notes, and snippets.

@devn
Forked from manveru/foo.rb
Created February 10, 2012 21:49
Show Gist options
  • Save devn/1793199 to your computer and use it in GitHub Desktop.
Save devn/1793199 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