Class: OptionParser
- Inherits:
-
Object
- Object
- OptionParser
- Defined in:
- lib/optparse_ex.rb
Instance Attribute Summary collapse
-
#p ⇒ Object
readonly
Returns the value of attribute p.
Instance Method Summary collapse
Instance Attribute Details
#p ⇒ Object (readonly)
Returns the value of attribute p.
7 8 9 |
# File 'lib/optparse_ex.rb', line 7 def p @p end |
Instance Method Details
#_on ⇒ Object
8 |
# File 'lib/optparse_ex.rb', line 8 alias :_on :on |
#on(attr, *args, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/optparse_ex.rb', line 9 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.first =~ /^\-/ self.send(attr.to_s+"=", args.shift) 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 |