Basic help about "require"

Hi All,

I have 2 folders.

Folder1 --> folder name "child" --> it contains child1.rb

Folder1 --> folder name "parent" --> it contains parent1.rb

MY NEED"

parent.rb

require '../child/child1'

It is giving error.

I want to require child1.rb in parent1.rb.

Please help to solve this issue.

Thanks

···

--
Posted via http://www.ruby-forum.com/.

Hi All,

I got a solution but i think its not a proper one.

Solution

Dir[File.join(File.dirname(__FILE__), 'child', "*.rb")].each do |file|
   require file
end

Any other solutions ?

···

--
Posted via http://www.ruby-forum.com/.

At windows platform
you need a complete path of the file

···

2009/6/14 Raveendran Perumalsamy <jazzezravi@gmail.com>

Hi All,

I got a solution but i think its not a proper one.

Solution

Dir[File.join(File.dirname(__FILE__), 'child', "*.rb")].each do |file|
  require file
end

Any other solutions ?
--
Posted via http://www.ruby-forum.com/\.

Hi,
In parent1.rb, try this:

require File.join(File.dirname(__FILE__), '..', 'child', 'child1')

Cheers,
Jits

···

2009/6/14 张昊昱 <deathyzhang@gmail.com>

2009/6/14 Raveendran Perumalsamy <jazzezravi@gmail.com>

> Hi All,
>
> I got a solution but i think its not a proper one.
>
>
> Solution
>
> Dir[File.join(File.dirname(__FILE__), 'child', "*.rb")].each do |file|
> require file
> end
>
>
> Any other solutions ?
> --
> Posted via http://www.ruby-forum.com/\.
>
>
At windows platform
you need a complete path of the file