Module: CommandProc::ClassMethods
- Defined in:
- lib/command_proc.rb
Instance Method Summary collapse
Instance Method Details
#get_instance(name) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/command_proc.rb', line 31 def get_instance(name) if self.instances[name] self.instances[name] else self.instances[name] = self.new(name) end self.instances[name] end |
#init_instances ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/command_proc.rb', line 19 def init_instances class_eval <<-CODE def self.instances @@instances ||= nil end def self.instances=(value) @@instances = value end @@instances = {} CODE end |
#invoke(args) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/command_proc.rb', line 40 def invoke(args) instance = get_instance(nil) command = args.shift if command == nil command = "help" end if instance.respond_to?(command) instance.send(command, args) elsif args.length >= 1 && instance.respond_to?(args[0]) name = command instance = get_instance(name) command = args.shift instance.send(command, args) else raise("argument '" + command + "' not recognized as command") end end |