Class: TuringMachine::CommandLineParser
- Inherits:
-
Object
- Object
- TuringMachine::CommandLineParser
- Defined in:
- lib/turing_machine/command_line_parser.rb
Instance Method Summary collapse
- #help ⇒ Object
-
#initialize(args) ⇒ CommandLineParser
constructor
A new instance of CommandLineParser.
- #parse ⇒ Object
Constructor Details
#initialize(args) ⇒ CommandLineParser
Returns a new instance of CommandLineParser.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/turing_machine/command_line_parser.rb', line 8 def initialize(args) @args = args = OpenStruct.new .tape = '0' @opt_parser = OptionParser.new do |opts| opts. = "Usage: turing_machine instruction_set [options]" opts.on("-t", "--tape DATA", "Initialize the tape with DATA") do |data| .tape = data end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end opts.on_tail("--version", "Show version") do puts VERSION exit end end end |
Instance Method Details
#help ⇒ Object
37 38 39 |
# File 'lib/turing_machine/command_line_parser.rb', line 37 def help @opt_parser.help end |
#parse ⇒ Object
32 33 34 35 |
# File 'lib/turing_machine/command_line_parser.rb', line 32 def parse @opt_parser.parse!(@args) end |