lib/textbringer/commands.rb in textbringer-0.1.8 vs lib/textbringer/commands.rb in textbringer-0.1.9

- old
+ new

@@ -2,29 +2,41 @@ require "open3" require "io/wait" module Textbringer + Command = Struct.new(:name, :block, :doc) + module Commands include Utils - @@command_list = [] + @command_table = {} def self.list - @@command_list + @command_table.keys end - def define_command(name, &block) + def self.command_table + @command_table + end + + def self.[](name) + @command_table[name.intern] + end + + def define_command(name, doc: "No documentation", &block) + name = name.intern Commands.send(:define_method, name, &block) - @@command_list << name if !@@command_list.include?(name) + Commands.command_table[name] = Command.new(name, block, doc) name end module_function :define_command def undefine_command(name) - if @@command_list.include?(name) + name = name.intern + if Commands.command_table.key?(name) Commands.send(:undef_method, name) - @@command_list.delete(name) + Commands.command_table.delete(name) end end module_function :undefine_command end end