Make delegated methods private
For those using Rails 6+, thanks to Tomas Valent now you can pass the private option to make the delegated methods private:
delegate :method, to: :object, private: true
Because delegate
returns a list of the symbols passed in you can chain the method calls like this:
private *delegate(:foo, :bar, :to => :baz)
Monkey patch Module
to add a helper method, just like what ActionSupport
pack does:
class Module
def private_delegate *methods
self.delegate *methods
methods.each do |m|
unless m.is_a? Hash
private(m)
end
end
end
end
# then
class Walrus
private_delegate :+, :to => :bubbles
def bubbles
0
end
end