Skip to content

Instantly share code, notes, and snippets.

@baccigalupi
Created December 3, 2009 05:32
Show Gist options
  • Save baccigalupi/247917 to your computer and use it in GitHub Desktop.
Save baccigalupi/247917 to your computer and use it in GitHub Desktop.
# 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