Skip to content

Instantly share code, notes, and snippets.

@miwarin
Created April 30, 2014 10:49
Show Gist options
  • Save miwarin/d238815cb4cd6924e108 to your computer and use it in GitHub Desktop.
Save miwarin/d238815cb4cd6924e108 to your computer and use it in GitHub Desktop.
コマンドパターン
#: 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