Created
October 12, 2010 04:13
-
-
Save sj26/621650 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/all' | |
class Blah | |
def foo | |
'foo!' | |
end | |
end | |
module Things | |
def self.included(base) | |
base.class_eval do | |
unless instance_methods.map(&:to_sym).include? :foo_without_things | |
alias_method :foo_without_things, :foo | |
end | |
alias_method :foo, :foo_with_things | |
end | |
end | |
def foo_with_things | |
foo_without_things.sub /(\W?)$/, " with things\\1" | |
end | |
end | |
Blah.new.foo | |
# => "foo!" | |
Blah.send :include, Things | |
Blah.new.foo | |
# => "foo with things!" | |
Blah.send :include, Things | |
Blah.new.foo | |
# => "foo with things!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment