Last active
May 11, 2017 12:52
-
-
Save cmar/3b861c3bfe0637938b495413a5c00116 to your computer and use it in GitHub Desktop.
example of prepended class methods
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
class Foo | |
def self.say | |
p "hello from Foo" | |
end | |
end | |
module Bar | |
def self.say | |
super | |
p "hello from Bar" | |
end | |
end | |
Foo.say # => "hello from Foo" | |
Foo.prepend Bar | |
Foo.say # => "hello from Foo" | |
Foo.class_eval do | |
prepend Bar | |
end | |
Foo.say # => "hello from Foo" | |
Foo.singleton_class.prepend Bar | |
Foo.say # => "hello from Foo" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment