Ti sfugge che irb non serve per quello che la stai usando tu.
irb è pensato per eseguire statement, non per il testing di uno script. A quello scopo esistono l'interprete e soprattutto gli unit test.
codice:
require 'rubygems'
require 'ostruct'
class App
VERSION = '0.0.1'
attr_reader :options
attr_reader :arguments
def initialize(arguments, stdin)
@arguments = arguments
@stdin = stdin
@options = OpenStruct.new
end
def run
end
end
app = App.new(ARGV, STDIN)
app.run
if __FILE__ == $0
require 'test/unit'
class AppTest < Test::Unit::TestCase
def setup
@app = App.new(ARGV, STDIN)
end
def test_initialize_should_set_arguments_from_command_line
assert_equal ARGV.sort, @app.arguments.sort
end
end
end
codice:
$ ruby app.rb
Loaded suite app
Started
.
Finished in 0.00023 seconds.
1 tests, 1 assertions, 0 failures, 0 errors