Class: Dice::Parser
- Inherits:
-
Object
- Object
- Dice::Parser
- Defined in:
- lib/dice/parser.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(args) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(args) ⇒ Parser
Returns a new instance of Parser.
8 9 10 11 |
# File 'lib/dice/parser.rb', line 8 def initialize(args) = {} @args = args end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/dice/parser.rb', line 6 def end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dice/parser.rb', line 13 def call OptionParser.new do |parser| parser. = 'Usage: dice [options]' parser.version = Dice::VERSION parser.on('-f', '--faces N', Integer, 'Roll the dice with N faces.') do |faces| [:faces] = faces end parser.on('-c', '--count COUNT', Integer, 'Roll the dice COUNT times.') do |count| [:count] = count end parser.on('-h', '--help', 'Show this help message.') do puts parser exit end end.parse!(@args) end |