Class: OptionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/workflow_manager/optparse_ex.rb

Overview

Version = ‘20130517-120455’

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pObject (readonly)

Returns the value of attribute p.



8
9
10
# File 'lib/workflow_manager/optparse_ex.rb', line 8

def p
  @p
end

Instance Method Details

#_onObject



9
# File 'lib/workflow_manager/optparse_ex.rb', line 9

alias :_on :on

#on(attr, *args, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/workflow_manager/optparse_ex.rb', line 10

def on(attr, *args, &block)
  if attr.is_a?(Symbol)
    self.class.class_eval do
      unless method_defined?(attr)
        attr_accessor attr 
      else
        raise "Method #{attr.to_s} is already defined in OptionParser class"
      end
    end
    unless args[0] =~ /\-/
      default = args.shift
      self.send(attr.to_s+"=", default)
    end
    _on(*args) do |i|
      self.send(attr.to_s+"=", i)
      block.call(i) if block
    end
  else
    args.unshift attr
    _on(*args, block)
  end
end