Skip to content

Instantly share code, notes, and snippets.

@cmar
Last active May 11, 2017 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cmar/3b861c3bfe0637938b495413a5c00116 to your computer and use it in GitHub Desktop.
Save cmar/3b861c3bfe0637938b495413a5c00116 to your computer and use it in GitHub Desktop.
example of prepended class methods
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