# Ruby Module

**URL:** <https://rubytalk.org/t/ruby-module/54277>\
**Category:** ruby-talk\
**Created:** [7 July 2009 07:26 UTC](https://rubytalk.org/t/ruby-module/54277 "2009-07-07T07:26:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vetrivel\_Vaithilinga](https://avatars.discourse-cdn.com/v4/letter/v/958977/32.png) [@Vetrivel\_Vaithilinga](https://rubytalk.org/u/Vetrivel_Vaithilinga)\
**Post date:** [7 July 2009 07:26 UTC](https://rubytalk.org/t/ruby-module/54277/1 "2009-07-07T07:26:30Z")

</div>

I have written some of the funcions in a file . The filename is test.rb  
Examples  
test.rb has only the following functions .  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def hai(a,b)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "This is Hai"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def hellow  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "This is Hellow"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

In check.rb I have required test.rb file . Then I used below hai method.  
It works .  
The check.rb file has  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;require 'test'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hai(1,2)

When I running this program in command line it works . But I am calling  
check.rb program from perl using system call . Some times it works fine  
. Some time It doesn't work . I got some error in my code . The Error  
is ' Wrong no of argument error' .  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system(check.rb).  
I am running above code from perl . To check the problem , I am  
redirecting the stderr to a file . I got Wrong 'no of argument error' .

check.rb is an executable file .

My Solution  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I think that we should not require a file without module . I  
request you t share your experience .

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [7 July 2009 07:53 UTC](https://rubytalk.org/t/ruby-module/54277/2 "2009-07-07T07:53:17Z")

</div>

> I have written some of the funcions in a file . The filename is test.rb  
> Examples  
> test.rb has only the following functions .  
> def hai(a,b)  
> puts "This is Hai"  
> end
> 
> ```
> def hellow
> puts &quot;This is Hellow&quot;
> end
> 
> ```
> 
> In check.rb I have required test.rb file . Then I used below hai method.  
> It works .  
> The check.rb file has  
> require 'test'  
> hai(1,2)
> 
> When I running this program in command line it works . But I am calling  
> check.rb program from perl using system call . Some times it works fine  
> . Some time It doesn't work . I got some error in my code . The Error  
> is ' Wrong no of argument error' .  
> system(check.rb).  
> I am running above code from perl . To check the problem , I am  
> redirecting the stderr to a file . I got Wrong 'no of argument error' .
> 
> check.rb is an executable file .

Do you have set the shebang line properly? Did you make sure that  
your load path is configured in a way that check.rb finds the proper  
test.rb?

> My Solution  
> I think that we should not require a file without module .

I am not sure what you are trying to say here but I doubt that this  
will solve your issue.

> I request you t share your experience .

A better way to put this would have been "please share your experience".

Regards

robert

> **···**
>
> 2009/7/7 Vetrivel Vetrivel \<vetrivel.bksys@gmail.com\>:
> 
> --  
> remember.guy do |as, often| as.you\_can - without end  
> [http://blog.rubybestpractices.com/](http://blog.rubybestpractices.com/)

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [7 July 2009 08:45 UTC](https://rubytalk.org/t/ruby-module/54277/3 "2009-07-07T08:45:31Z")

</div>

Vetrivel Vetrivel wrote:

> I am running above code from perl . To check the problem , I am  
> redirecting the stderr to a file . I got Wrong 'no of argument error' .

Can you paste the \*exact\* and \*complete\* error message you see? This  
will make it clear whether the error comes from Perl or Ruby, and if  
Ruby, exactly which line it is on.

The only problem I can see is that "require 'test'" assumes that test.rb  
is in the current working directory. Perl may have changed the current  
working directory. You could write instead:

&nbsp;&nbsp;require File.join(File.dirname(\_\_FILE\_\_), 'test')

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
