Created
April 30, 2014 10:49
-
-
Save miwarin/d238815cb4cd6924e108 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
#: coding: utf-8 | |
class Command | |
def initialize() | |
@command ||= {} | |
end | |
def register(name, cmd) | |
@command[name] = cmd | |
end | |
def exec(name) | |
@command[name] | |
end | |
end | |
def func0() | |
puts "func0" | |
end | |
def func1() | |
puts "func1" | |
end | |
def func2() | |
puts "func2" | |
end | |
def main(argv) | |
command = Command.new | |
command.register("a", func0) | |
command.register("b", func1) | |
command.register("c", func2) | |
command.exec("a") | |
command.exec("b") | |
command.exec("c") | |
end | |
main(ARGV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment