newbie question - undefined method `replace_session_timeout' for main:Object (NoMethodError)

W

warrene33

Hi,

I'm a newbie to ruby, and programming really...

I'm trying to write a simple script that will make a small change to a
text file.

Here's the code:

#script for changing the sessionState timeout to 30 minutes

f = File.open('C:\Inetpub\wwwroot\GT\web.config', 'r+')
f.each do |line|
if /sessionState/ =~line
offset=line.length
line=replace_session_timeout line
f.seek(-offset, IO::SEEK_CUR)
f.print line
end
end
f.close

def replace_session_timeout line
int = /</=~line
spacer = line[0..int-1]
result=line.replace spacer + "<sessionState timeout=\"30\"/>\r\n"
end

When I run this script I get the following error:
ruby GT_SessionTimeout_1.rb
GT_SessionTimeout_1.rb:7: undefined method `replace_session_timeout'
for main:Object (NoMethodError)
from GT_SessionTimeout_1.rb:4:in `each'
from GT_SessionTimeout_1.rb:4
Exit code: 1

I guess there is something wrong with my method call, but it looks
syntactically correct to me.

I've paged through the pickaxe book and online but, to be honest, I
don't think I understand the problem enough to search well for a
solution.

Any ideas?

Thanks much,
Warren
 
M

Morton Goldberg

#script for changing the sessionState timeout to 30 minutes

f = File.open('C:\Inetpub\wwwroot\GT\web.config', 'r+')
f.each do |line|
if /sessionState/ =~line
offset=line.length
line=replace_session_timeout line
f.seek(-offset, IO::SEEK_CUR)
f.print line
end
end
f.close

def replace_session_timeout line
int = /</=~line
spacer = line[0..int-1]
result=line.replace spacer + "<sessionState timeout=\"30\"/>\r\n"
end

When I run this script I get the following error:
ruby GT_SessionTimeout_1.rb
GT_SessionTimeout_1.rb:7: undefined method `replace_session_timeout'
for main:Object (NoMethodError)
from GT_SessionTimeout_1.rb:4:in `each'
from GT_SessionTimeout_1.rb:4
Exit code: 1

I guess there is something wrong with my method call, but it looks
syntactically correct to me.

The Ruby interpreter needs to see the definition of
replace_session_timeout before it is called for the first time. Just
move the definition above the body of the script.

Regards, Morton
 
W

warrene33

#script for changing the sessionState timeout to 30 minutes
f = File.open('C:\Inetpub\wwwroot\GT\web.config', 'r+')
f.each do |line|
if /sessionState/ =~line
offset=line.length
line=replace_session_timeout line
f.seek(-offset, IO::SEEK_CUR)
f.print line
end
end
f.close
def replace_session_timeout line
int = /</=~line
spacer = line[0..int-1]
result=line.replace spacer + "<sessionState timeout=\"30\"/>\r\n"
end
When I run this script I get the following error:
GT_SessionTimeout_1.rb:7: undefined method `replace_session_timeout'
for main:Object (NoMethodError)
from GT_SessionTimeout_1.rb:4:in `each'
from GT_SessionTimeout_1.rb:4
I guess there is something wrong with my method call, but it looks
syntactically correct to me.

The Ruby interpreter needs to see the definition of
replace_session_timeout before it is called for the first time. Just
move the definition above the body of the script.

Regards, Morton

Wow. That simple. Thanks
Warren
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top