Skip to content

Instantly share code, notes, and snippets.

@pjb3 pjb3/query.rb
Created Mar 20, 2013

Embed
What would you like to do?
It's things like this that make Ruby fun :)
class Query
def initialize
@hash = {}
end
def method_missing(name, *args)
value = args.length > 0 ? args.first : true
@hash.merge!(name => value)
self
end
def to_hash
@hash.dup
end
end
puts Query.new.male.from('baltimore').age(greater_than: 21).in([21230, 21210]).to_hash.inspect
# => {:male=>true, :from=>"baltimore", :age=>{:greater_than=>21}, :in=>[21230, 21210]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.