Skip to content

Instantly share code, notes, and snippets.

@danielcooper
Created August 12, 2012 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielcooper/3332095 to your computer and use it in GitHub Desktop.
Save danielcooper/3332095 to your computer and use it in GitHub Desktop.
chaining example
class Search
class << self
def where(args)
Search.new(args)
end
end
def initialize(args)
@search_arguments = args
end
def where(args)
@search_arguments.merge!(args)
self
end
def each
results.each{|a| yield(a)}
end
def results
#Go and get some results!
end
end
#irb(main):084:0> Search.where(:foo => 'bar').where(:magic_number => 3)
#=> #<Search:0x10aa5e9d8 @search_arguments={:foo=>"bar", :magic_number=>3}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment