Skip to content

Instantly share code, notes, and snippets.

@alissonbrunosa
Last active October 1, 2017 13:53
Show Gist options
  • Save alissonbrunosa/ef664437a1d1b298b73786a2dfc76db3 to your computer and use it in GitHub Desktop.
Save alissonbrunosa/ef664437a1d1b298b73786a2dfc76db3 to your computer and use it in GitHub Desktop.
module Chainable
def chain(*methods)
chain!(*methods)
rescue NoMethodError
nil
end
def chain!(*methods)
methods.inject(self) do |object, method|
object.public_send(method)
end
end
end
class Object
include Chainable
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment