Skip to content

Instantly share code, notes, and snippets.

@umar-webonise
Created July 21, 2015 13:13
Show Gist options
  • Save umar-webonise/8c0d65f490153794e552 to your computer and use it in GitHub Desktop.
Save umar-webonise/8c0d65f490153794e552 to your computer and use it in GitHub Desktop.
Best Way to Include and Extend a Module Method
module Swingable
def self.included(base)
base.extend(Swingable)
end
def swing
puts 'Did a swing!'
end
end
class User
include Swingable
end
User.swing # => 'Did a swing!'
User.new.swing # => 'Did a swing!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment