# Unable to open the script in anouther script

**URL:** <https://www.ruby-forum.com/t/unable-to-open-the-script-in-anouther-script/134248>\
**Category:** Ruby\
**Created:** [April 9, 2008, 9:03am UTC](https://www.ruby-forum.com/t/unable-to-open-the-script-in-anouther-script/134248 "2008-04-09T09:03:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pranjal\_jain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ac91a4/32.png) [@pranjal\_jain](https://www.ruby-forum.com/u/pranjal_jain)\
**Post date:** [April 9, 2008, 9:03am UTC](https://www.ruby-forum.com/t/unable-to-open-the-script-in-anouther-script/134248/1 "2008-04-09T09:03:26Z")

</div>

Hi All  
I ma trying to call the function written in one script in other script.  
But it is giving me the error.

The called script is 2.rb

require ‘watir’  
def test\_b

$ie1 = IE.new

$ie1.text\_field(:name, “q”).set “pickaxe”  
$ie1.button(:name, “btnG”).click  
#ie.showAllObjects  
end

the calling script is 1.rb

require ‘watir’  
require ‘2’

class TestCase

def test\_a  
$ie = IE.new  
$ie.goto ‘[www.google.com](http://www.google.com)’  
end  
test\_b  
end

The error popped is as follows:

./2.rb:4: in ‘test\_b’: uninitialized constant IE(NameError)  
from 1.rb:10

Please help.  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![pranjal\_jain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ac91a4/32.png) [@pranjal\_jain](https://www.ruby-forum.com/u/pranjal_jain)\
**Post date:** [April 9, 2008, 2:00pm UTC](https://www.ruby-forum.com/t/unable-to-open-the-script-in-anouther-script/134248/2 "2008-04-09T14:00:42Z")

</div>

2008/4/9, Pranjal J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> class TestCase
> 
> ./2.rb:4: in ‘test\_b’: uninitialized constant IE(NameError)  
> from 1.rb:10

I’ve never used Watir myself, but looking at the API docs it  
looks like you should replace references to IE with  
Watir::IE.

HTH,  
Stefan

---

<div class="post-metadata">

**Author:** ![pranjal\_jain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ac91a4/32.png) [@pranjal\_jain](https://www.ruby-forum.com/u/pranjal_jain)\
**Post date:** [April 9, 2008, 11:59pm UTC](https://www.ruby-forum.com/t/unable-to-open-the-script-in-anouther-script/134248/3 "2008-04-09T23:59:31Z")

</div>

Ruby is complaining that there’s an uninitialized constant called  
IE… which means (funnily enough) that it doesn’t know what IE means.

This is probably because you’re trying to use a constant which is  
namespaced without the namespace!

also, I think that you probably used to use php, given the  
nomenclature you’re using, and the fact that you’re putting $ chars in  
front of all your variable names.

Don’t do this. $ in front of a variable name means it’s a global, and  
I’m fairly sure you don’t want globals all through your code.

This is what you probably wanted: (from the watir example page)

ie = Watir::IE.new

Julian.

Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)  
VIDEO #3 out NOW!  
[http://sensei.zenunit.com/](http://sensei.zenunit.com/)

---

<div class="post-metadata">

**Author:** ![pranjal\_jain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ac91a4/32.png) [@pranjal\_jain](https://www.ruby-forum.com/u/pranjal_jain)\
**Post date:** [April 9, 2008, 6:41pm UTC](https://www.ruby-forum.com/t/unable-to-open-the-script-in-anouther-script/134248/4 "2008-04-09T18:41:05Z")

</div>

On Apr 9, 3:03 am, Pranjal J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> class TestCase  
> /2.rb:4: in ‘test\_b’: uninitialized constant IE(NameError)  
> from 1.rb:10
> 
> ## Please help. Thanks in advance.
> 
> Posted viahttp://www.ruby-forum.com/.

Remember that ruby is interpreted, and code is evaluated line by line

> class TestCase  
> def test\_a  
> $ie = IE.new  
> $ie.goto ‘[www.google.com](http://www.google.com)’  
> end  
> test\_a is defined but has NOT been executed  
> test\_b  
> test\_ is invoked here, the code is executed  
> Since test\_a has not been executed yet $ie has not been defined  
> end

I’d suggest:  
class TestCase  
def test\_a  
$ie = IE.new  
$ie.goto ‘[www.google.com](http://www.google.com)’  
test\_b  
end  
end
