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 "  def self.instances\n      @@instances ||= nil\n  end\n  def self.instances=(value)\n      @@instances = value\n  end\n  @@instances = {}\n  CODE\nend\n"

#invoke(args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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)
  else
    name = command
    instance = get_instance(name)
    puts "instance is " + instance.to_s
  end
end