0.0
No commit activity in last 3 years
No release in over 3 years
Add a method that you can hang other methods.
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, ~> 0
>= 2.14.0, ~> 2.14.0
 Project Readme

Hanging Methods - Add a method that you can hang other methods

This is the gem for building nice looking APIs where you want to delegate method calls to another object at a later time.

See Parallizer for an example.

Installation

gem install hanging_methods

Hanging some methods

Here's an example.

require 'hanging_methods'

class Interesting
  include HangingMethods

  add_hanging_method :add
end

interesting = Interesting.new
interesting.add.a_method
interesting.add.another_method(1, 2)

puts interesting.hanging_method_invocations(:add)
# [[:a_method], [:another_method, 1, 2]]

Get notified of a hanging method

You can be notified of method being hanged and specify its result.

require 'hanging_methods'

class Interesting
  include HangingMethods

  add_hanging_method :add, after_invocation: :added

  private

  def added(method_name, arg_1, arg_2, &block)
    return "very_interesting: #{arg_1}, #{arg_2}, #{yield}"
  end
end

interesting = Interesting.new
interesting.add.a_method(1, 2) { 3 }
# returns "very_interesting: 1, 2, 3"

Credits

Hanging Methods is maintained by Michael Pearce

Copyright

Copyright (c) 2013 Michael Pearce. See LICENSE.txt for further details.