Skip to content

Instantly share code, notes, and snippets.

@cmar

cmar/prepended.rb

Last active May 11, 2017
Embed
What would you like to do?
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