Created
March 5, 2015 14:45
-
-
Save fiedl/1285f07ee99e546ecd37 to your computer and use it in GitHub Desktop.
Prepend: Using `super` in a re-opened ruby class.
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
# Original class | |
class Foo | |
def piep | |
"sag mal" | |
end | |
end | |
# Methods to add/override | |
module FooExtension | |
def piep | |
"#{super} piep" | |
end | |
end | |
# Reopened class | |
class Foo | |
prepend FooExtension | |
end | |
p Foo.new.piep | |
# => "sag mal piep" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment