Created
December 3, 2009 05:32
-
-
Save baccigalupi/247917 to your computer and use it in GitHub Desktop.
This file contains 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
# Available operators for overloading criteria interactions | |
# + & | < > <= >= =~ == <=> | |
# criteria creator for matching a hash/array value at a particular location | |
# good for hash/array objects or their derivatives | |
Klass.query do |obj| | |
obj[3] == "something" | | |
obj[:key] == "value" | |
# obj.has_value(my_value, :at => :key) | |
# has_value is alt syntax, could include options for :key/:index to specify hash or array | |
# could also receive options that restrict class, etc | |
end | |
# instance variables | |
Klass.query do |obj| | |
obj.variable(:ivar_name) == "something" | |
# obj.var(:ivar_name) == "something" # alias for variable | |
# obj.has('@stuff') = {:this => 'that'} # alias for has | |
end | |
# mixing them up | |
Klass.query do |obj| | |
obj.variable(:ivar_name)['key'] =~ /something/ | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment