# Newbie question - undefined method \`replace\_session\_timeout'

**URL:** <https://www.ruby-forum.com/t/newbie-question-undefined-method-replace-session-timeout/107480>\
**Category:** Ruby\
**Created:** [June 22, 2007, 4:36am UTC](https://www.ruby-forum.com/t/newbie-question-undefined-method-replace-session-timeout/107480 "2007-06-22T04:36:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 22, 2007, 4:36am UTC](https://www.ruby-forum.com/t/newbie-question-undefined-method-replace-session-timeout/107480/1 "2007-06-22T04:36:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 22, 2007, 4:59am UTC](https://www.ruby-forum.com/t/newbie-question-undefined-method-replace-session-timeout/107480/2 "2007-06-22T04:59:20Z")

</div>

On Jun 21, 2007, at 10:35 PM, removed\_email\_address@domain.invalid wrote:

> end  
> 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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 22, 2007, 2:28pm UTC](https://www.ruby-forum.com/t/newbie-question-undefined-method-replace-session-timeout/107480/3 "2007-06-22T14:28:23Z")

</div>

On Jun 21, 10:58 pm, Morton G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ```
> > line=replace_session_timeout line
> > 
> > ```
> > 
> > end  
> > 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
