Created
March 20, 2013 14:09
-
-
Save pjb3/5204928 to your computer and use it in GitHub Desktop.
It's things like this that make Ruby fun :)
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 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