Created
June 23, 2015 18:38
-
-
Save ajbeach2/d710b48754053191f726 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
module Runnable | |
def run(command, *args) | |
fail "#{command} is not a valid action!" unless actions.include? command | |
send(command, *args) | |
end | |
def runnables(*args) | |
define_singleton_method(:actions) do | |
args.map(&:to_s) | |
end | |
end | |
end | |
class MyObj | |
extend Runnable | |
runnables :hello | |
def self.hello(name) | |
puts "hello #{name}" | |
end | |
end | |
puts MyObj.actions # ["hello"] | |
puts MyObj.run("hello", "Bob") #hello bob |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment