[a] can't convert nil into String (TypeError)

A

aidy

Hi,

Can anyone tell me what the problem with this code is?


<snip>

class Test_log

def read_step_log (filepath)


@filepath = filepath

f = File.open(@filePath, "r")


while(f.gets)
if /START TESTCASE|FAILED/
print
end
end

f.close
end
end

foo = Test_log.new
foo.read_step_log('C:\Ruby_Files\StepLog.txt')


</snip>


I am getting a `initialize': can't convert nil into String (TypeError)


Thanks

Aidy
 
R

rajeevnair32

The error is in your variable name. you had accidently used "filePath"
instead of "filepath".

class Test_log
def read_step_log (filepath)
f = File.open(filepath, "r")
while(f.gets)
print if /START TESTCASE|FAILED/
end
f.close
end
end

Test_log.new.read_step_log("a.rb")
 
A

aidy

The error is in your variable name. you had accidently used "filePath"
instead of "filepath".


I apologise for that; I am from a Visual Basic background.

How am I supposed to flag silly mistakes like that with dynamic typing?

Cheers

Aidy
 
R

rajeevnair32

I know in perl, there is some like "use strict;". I believe ruby should
have some thing similar.
 
B

bwv549

alternative to running: ruby -w
you can put the flag at the top of your file:
#!/usr/bin/ruby -w
 
C

ChrisH

If the script is being run on a *NIX environment.

Given the OP has VB background, he's proibably on Windows...
 
G

Gregor Kopp

class Test

def initialize(argument)
puts "now im in initialize..."
@argument = argument
end

def dosomethingheyho
puts "now im in dosemethingheyho..."
puts @argument
end

end

testitman = Test.new("blah")
testitman.dosomethingheyho


If you want to pass an argument to a class, then you could also use
initialize, which is called on initialization of a class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top