Created
April 29, 2014 20:02
-
-
Save jnaglick/386c748aa8ab45507d4f to your computer and use it in GitHub Desktop.
metaprogramming wrappers
This file contains hidden or 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
module ConfigurableMethods | |
def configure_methods(methods_to_configure) # {:method_name => :method_override_name, ...} | |
Class.new(self) do | |
methods_to_configure.each do |method_name, method_override_name| | |
class_exec do | |
alias_method method_name, method_override_name | |
end | |
end | |
end | |
end | |
end | |
class ActionDoer | |
extend ConfigurableMethods | |
def initialize | |
end | |
def do_action | |
:default_action | |
end | |
def do_something_else | |
:default_something_else | |
end | |
# would be nice if these could be private. arg | |
def do_action_differently | |
:different_action | |
end | |
def do_action_differently_still | |
:different_still_action | |
end | |
def do_something_else_differently | |
:different_something_else | |
end | |
end | |
class DifferentActionDoer < ActionDoer | |
alias_method :do_action, :do_action_differently | |
end |
Author
jnaglick
commented
Apr 29, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment