Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using Module Prepend To Extend Ruby Classes
class Foo
attr_reader :bar
def initialize
@bar = 'bar'
end
end
module Bar
def bar
super.upcase
end
end
Foo.prepend Bar
Foo.new.bar # => 'BAR'
# If include was used:
Foo.include Bar
Foo.new.bar # => 'bar'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.