Created
July 21, 2015 13:13
-
-
Save umar-webonise/8c0d65f490153794e552 to your computer and use it in GitHub Desktop.
Best Way to Include and Extend a Module Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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