Module: Console::ClassMethods
- Defined in:
- lib/console.rb
Instance Method Summary collapse
- #commands ⇒ Object
- #define_cmd(name, desc, &block) ⇒ Object
- #run_cmd(instance, cmd_name, args = []) ⇒ Object
Instance Method Details
#commands ⇒ Object
34 35 36 |
# File 'lib/console.rb', line 34 def commands @commands ||= {} end |
#define_cmd(name, desc, &block) ⇒ Object
16 17 18 19 20 |
# File 'lib/console.rb', line 16 def define_cmd(name, desc, &block) commands[name.to_s] = {desc: desc, block: block} define_method(command_method_name(name), &block) end |
#run_cmd(instance, cmd_name, args = []) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/console.rb', line 22 def run_cmd(instance, cmd_name, args = []) cmd_name = cmd_name.to_s if commands[cmd_name] instance.send(command_method_name(cmd_name), *args) else puts "Invalid command '#{cmd_name}'" end rescue => e puts e. end |