Skip to content

Instantly share code, notes, and snippets.

@fiedl
Created March 5, 2015 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fiedl/1285f07ee99e546ecd37 to your computer and use it in GitHub Desktop.
Save fiedl/1285f07ee99e546ecd37 to your computer and use it in GitHub Desktop.
Prepend: Using `super` in a re-opened ruby class.
# 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