Ruby Module

  • Thread starter Vetrivel Vetrivel
  • Start date
V

Vetrivel Vetrivel

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 "This is Hellow"
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 .

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

Robert Klemme

2009/7/7 Vetrivel Vetrivel said:
I have written some of the funcions in a file . The filename is test.rb
Examples
test.rb has only the =A0following functions .
=A0 =A0 =A0 =A0 =A0 =A0 def hai(a,b)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0puts "This is Hai"
=A0 =A0 =A0 =A0 =A0 =A0 end

=A0 =A0 =A0 =A0 =A0 =A0 def hellow
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0puts "This is Hellow"
=A0 =A0 =A0 =A0 =A0 =A0 end

In check.rb I have required test.rb file . Then I used below hai method.
It works .
The check.rb file has
=A0 =A0 =A0 require 'test'
=A0 =A0 =A0 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 =A0doesn't work . I got some error in my code . The Error
is ' Wrong no of argument =A0error' .
=A0 =A0 system(check.rb).
I am running above code from perl . =A0To check the problem , I am
redirecting the stderr to a file . I got Wrong 'no of argument error' .

=A0check.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?
 
B

Brian Candler

Vetrivel said:
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:

require File.join(File.dirname(__FILE__), 'test')
 

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

Forum statistics

Threads
474,173
Messages
2,570,938
Members
47,473
Latest member
pioneertraining

Latest Threads

Top