Skip to content

Instantly share code, notes, and snippets.

@sj26
Created October 12, 2010 04:13
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 sj26/621650 to your computer and use it in GitHub Desktop.
Save sj26/621650 to your computer and use it in GitHub Desktop.
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