ocra
ocra copied to clipboard
ocra giving trouble with File.open when command line argument is used
Here is my problem:
I have a file "file.txt", contents: This is a test file.
I have a test script "test.rb", contents: astr = ARGV[0] File.open(astr,"r").each { |line| puts line }
If I type "ruby test.rb file.txt" I get: This is a test file.
If I type "ocra test.rb" I get:
=== Loading script to check dependencies
C:/PATHTOSCRIPT/test.rb:2:in initialize': no implicit conversion of nil into String (TypeError) from C:/PATHTOSCRIPT/test.rb:2:in
open'
from C:/PATHTOSCRIPT/test.rb:2:in <top (required)>' from C:/Ruby22/lib/ruby/gems/2.2.0/gems/ocra-1.3.5/bin/ocra:1185:in
load'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/ocra-1.3.5/bin/ocra:1185:in <top (required)>' from C:/Ruby22/bin/ocra:23:in
load'
from C:/Ruby22/bin/ocra:23:in `
What am I doing wrong?
Oh yeah. This is using ruby 2.2.2 on Windows 7 x64
Clearly ARGV[0]
is nil in the second case since nothing was passed.