0.0
No commit activity in last 3 years
No release in over 3 years
Chain methods to specify parameters
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
 Project Readme

Parameter Chain

Parameter Chain allows you to chain methods to specify parameters, e.g.

instance.bar(123).baz(321)

Which would be equivalent to:

instance.some_method(:bar => 123, :baz => 321)

Parameter Chain provides a great out-of-the-box interface for dealing with search, or querying an API:

api = SomeApi.new(key)
api.category(3).price('> 1000').brand(:apple)

Which would be equivalent to:

api = SomeApi.new(key)
api.search(:category => 3, :price => '> 1000', :brand => :apple)

Setup

gem install parameter_chain
require 'parameter_chain'

class MyClass
  def my_method(params = {})
    # Do something with params, e.g.
    "Params: #{params.inspect}"
  end
  parameter_chain :my_method, :foo, :bar
end

instance = MyClass.new
instance.foo(123).bar(321)
#=> "Params: { :foo => 123, :bar => 321 }"

Lazy Evaluation

Parameter chains are evaluated lazily. When you call something on the end of your chain, it passes the parameters to the method and evaluates.

If you're in IRB, the inspect method is called implicitly. This is why your chains look like hashes. You can verify this by running:

instance.foo(123).bar(321).__class__
#=> ParameterChain

Coming Soon

Chaining from class methods, e.g.

MyClass.foo(123).bar(321)