Created
February 10, 2012 21:41
-
-
Save manveru/1793151 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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