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
33 34 35 |
# File 'lib/console.rb', line 33 def commands @commands ||= {} end |
#define_cmd(name, desc, &block) ⇒ Object
16 17 18 |
# File 'lib/console.rb', line 16 def define_cmd(name, desc, &block) commands[name.to_s] = {desc: desc, block: block} end |
#run_cmd(instance, cmd_name, args = []) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/console.rb', line 20 def run_cmd(instance, cmd_name, args = []) cmd_name = cmd_name.to_s command = commands[cmd_name] if command instance.instance_exec(*args, &command[:block]) else puts "Invalid command '#{cmd_name}'" end rescue => e puts e. end |