Skip to content

Instantly share code, notes, and snippets.

@metaskills
Created May 11, 2017 01:03
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 metaskills/5e062c74b87f176246e4b7ac5f10d541 to your computer and use it in GitHub Desktop.
Save metaskills/5e062c74b87f176246e4b7ac5f10d541 to your computer and use it in GitHub Desktop.
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