Skip to content

Instantly share code, notes, and snippets.

@lsegal
Created February 28, 2013 08:02
Show Gist options
  • Save lsegal/5055063 to your computer and use it in GitHub Desktop.
Save lsegal/5055063 to your computer and use it in GitHub Desktop.
On a positive note, AOP with mixins just got way simpler in Ruby 2:
module Helper
def help
puts "Hello,"
super
end
end
class Foo
def help
puts "Do you need help?"
end
end
Foo.send(:prepend, Helper)
Foo.new.help
__DATA__
Prints:
Hello,
Do you need help?
@edward
Copy link

edward commented Mar 2, 2013

prepend is rad.

(I also continue to love Ruby’s __DATA__ declaration.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment