From: Saji Hameed Date: 2012-04-19T09:12:35+09:00 Subject: Re: Breaking large Ruby script into multiple files --f46d042d038c313e9704bdfd079e Content-Type: text/plain; charset=UTF-8 Following on Jake's advice and noting that you are familiar with Fortran modules, an easier first step would be to use modules in Ruby and start from there. The first.rb from Jake's example could be module Statistics def correlation(a,b) # code for correlation end def stddev(a) # code for standard deviation end end In second.rb, you could do require "./first" include Statistics # similar to USE in fortran a=[1,2,3,4] b=[0,0,0,0] correlation(a,b) stddev(a) saji -- On Thu, Apr 19, 2012 at 8:50 AM, jake kaiden wrote: > hi Thomas, > > you can use `require` to include any files that you want. > > try this - in the same directory, create two files: `first.rb` and > `second.rb` > > `first.rb` could look like this: > > Class Traveller > def initialize > puts "I'm from the first.rb!" > end > end > > ...and `second.rb` like this: > > require './first.rb' > # note: require 'first' will usually also work > > Traveller.new > > > do a search for `ruby require` or `ruby require_relative`, and you'll > find more info... > > hth- > > - j > > -- > Posted via http://www.ruby-forum.com/. > > -- Saji N Hameed, ARC-ENV, Center for Advanced Information Science and Technology, University of Aizu, Tsuruga, Ikki-machi, Aizuwakamatsu-shi, Fukushima 965-8580, Japan Tel: +81242 37-2736 Fax:+81242 37-2760 email: saji@u-aizu.ac.jp url: http://www.u-aizu.ac.jp bib: http://www.researcherid.com/rid/B-9188-2009 --f46d042d038c313e9704bdfd079e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Following on Jake's advice and noting that you are familiar with Fortra= n modules, an easier first step would
be to use modules in Ruby and star= t from there.

The first.rb from Jake's example could be

module Statistics
=C2=A0 def correlation(a,b)
=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 # code for correlation
=C2=A0 end

=C2=A0 def stddev(a)<= br>=C2=A0=C2=A0=C2=A0=C2=A0 # code for standard deviation
=C2=A0 end
= end

In second.rb, you could do
=C2=A0 require "./first"=
=C2=A0 include Statistics=C2=A0 # similar to USE in fortran
=C2=A0=C2=A0=
=C2=A0a=3D[1,2,3,4]
=C2=A0b=3D[0,0,0,0]

=C2=A0correlation(a,= b)
=C2=A0stddev(a)

saji
--

O= n Thu, Apr 19, 2012 at 8:50 AM, jake kaiden <lists@ruby-forum.com> wrote:=
hi Thomas,

=C2=A0you can use `require` to include any files that you want.

=C2=A0try this - in the same directory, create two files: `first.rb` and `second.rb`

`first.rb` could look like this:

Class Traveller
=C2=A0def initialize
=C2=A0 =C2=A0puts "I'm from the first.rb!"
=C2=A0end
end

=C2=A0...and `second.rb` like this:

require './first.rb'
# note: require 'first' will usually also work

Traveller.new


=C2=A0do a search for `ruby require` or `ruby require_relative`, and you&#= 39;ll
find more info...

=C2=A0hth-

=C2=A0- j



--

Saji N = Hameed,
ARC-ENV, Center for Advanced Information Science and Technology,=
University of Aizu, Tsuruga, Ikki-machi,
Aizuwakamatsu-shi, Fukushim= a 965-8580,
Japan
=C2=A0 =C2=A0 =C2=A0 =C2=A0
Tel: +81242 37-2736
Fax:+81242 = 37-2760
=C2=A0email: saji@u-aizu.ac.jp
=C2=A0url: http://www.u-aizu.ac.jp
=C2=A0bib: http://www.researcherid.com/rid/B-9188-2009
--f46d042d038c313e9704bdfd079e--