Last active
January 4, 2016 13:19
-
-
Save zeroeth/8626790 to your computer and use it in GitHub Desktop.
include override
This file contains hidden or 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 SwingableInstanceMethods | |
| def instance_swing | |
| puts 'Did an instance swing!' | |
| end | |
| end | |
| module SwingableClassMethods | |
| def static_swing | |
| puts 'Did a static swing!' | |
| end | |
| def include?(xyz) | |
| puts "XYZ" | |
| super # arguments are implicit | |
| end | |
| end | |
| class BaseballBat | |
| include SwingableInstanceMethods | |
| extend SwingableClassMethods | |
| end | |
| class SuperBat < BaseballBat | |
| end | |
| class OtherThing | |
| end | |
| BaseballBat.static_swing | |
| BaseballBat.new.instance_swing | |
| puts BaseballBat.include? SwingableInstanceMethods | |
| puts SuperBat.include? SwingableInstanceMethods | |
| puts OtherThing.include? SwingableInstanceMethods |
This file contains hidden or 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 include?(xyz) | |
| puts "XYZ" | |
| super # arguments are implicit | |
| end | |
| end | |
| class BaseballBat | |
| extend Swingable | |
| end | |
| class SuperBat < BaseballBat | |
| end | |
| class OtherThing | |
| end | |
| puts BaseballBat.include? Swingable | |
| puts SuperBat.include? Swingable | |
| puts OtherThing.include? Swingable | |
| # no such thing... | |
| puts BaseballBat.extend? Swingable |
This file contains hidden or 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(ClassMethods) | |
| end | |
| def instance_swing | |
| puts 'Did an instance swing!' | |
| end | |
| module ClassMethods | |
| def static_swing | |
| puts 'Did a static swing!' | |
| end | |
| def include?(xyz) | |
| puts "XYZ" | |
| super # arguments are implicit | |
| end | |
| end | |
| end | |
| class BaseballBat | |
| include Swingable | |
| end | |
| class SuperBat < BaseballBat | |
| end | |
| class OtherThing | |
| end | |
| BaseballBat.static_swing | |
| BaseballBat.new.instance_swing | |
| puts BaseballBat.include? Swingable | |
| puts SuperBat.include? Swingable | |
| puts OtherThing.include? Swingable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment