The first file is one.rb and defines an instanciable class named ‘One’.
The second file is two.rb and needs to create an instance of class ‘One’
as defined in one.rb.
The first file is one.rb and defines an instanciable class named ‘One’.
The second file is two.rb and needs to create an instance of class ‘One’
as defined in one.rb.
How do I import the class ‘One’ into two.rb?
Assuming the only class defined in one.rb is ‘One’ then you should be
able
to do:
require ‘one’
I thought ‘require’ only imported files in the Ruby lib folder.
powerbook:~ michaelguterl$ ri require
--------------------------------------------------------- Kernel#require
require(string) => true or false
Ruby tries to load the library named _string_, returning +true+ if
successful. If the filename does not resolve to an absolute path,
it will be searched for in the directories listed in +$:+. If the
file has the extension ``.rb'', it is loaded as a source file; if
the extension is ``.so'', ``.o'', or ``.dll'', or whatever the
default shared library extension is on the current platform, Ruby
loads the shared library as a Ruby extension. Otherwise, Ruby tries
adding ``.rb'', ``.so'', and so on to the name. The name of the
loaded feature is added to the array in +$"+. A feature will not be
loaded if it's name already appears in +$"+. However, the file name
is not converted to an absolute path, so that ``+require
'a';require './a'+'' will load +a.rb+ twice.
require "my-library.rb"
require
I thought ‘require’ only imported files in the Ruby lib folder.
Well it only loads files from paths that are in $: (aka $LOAD_PATH).
One of the paths that is in $LOAD_PATH by default is ‘.’, which is
the current working directory.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.