Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2617 > unrolled thread
| Started by | william nelson <wanelson23@gmail.com> |
|---|---|
| First post | 2011-04-11 04:26 -0500 |
| Last post | 2011-04-11 18:23 -0500 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.ruby
Beginner's Beginner william nelson <wanelson23@gmail.com> - 2011-04-11 04:26 -0500
Re: Beginner's Beginner 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-11 15:04 -0500
Re: Beginner's Beginner 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-11 18:23 -0500
| From | william nelson <wanelson23@gmail.com> |
|---|---|
| Date | 2011-04-11 04:26 -0500 |
| Subject | Beginner's Beginner |
| Message-ID | <5eb7523dd74392a56e954a3486b4830f@ruby-forum.com> |
I am trying to execute the Sudoku Solver listed in the book "The Ruby Programming Book" (pages 17 -24) The code for the Sudoku Module is available online but I do not understand the following instruction: require 'sudoku' puts Sudoku.solver(Sudoku::Puzzle.new(ARGF.readlines)) Can someone walk me through (baby-steps) how to actually "require" sudoku so that I can see the Module in action. The more explicit your answer the better since I am a newbee's newbee! -- Posted via http://www.ruby-forum.com/.
[toc] | [next] | [standalone]
| From | 7stud -- <bbxx789_05ss@yahoo.com> |
|---|---|
| Date | 2011-04-11 15:04 -0500 |
| Message-ID | <ab0373fb31c334955b289bb9cc4f9095@ruby-forum.com> |
| In reply to | #2617 |
william nelson wrote in post #992087:
> I am trying to execute the Sudoku Solver listed in the book "The Ruby
> Programming Book" (pages 17 -24)
>
> The code for the Sudoku Module is available online but I do not
> understand the following instruction:
>
> require 'sudoku'
> puts Sudoku.solver(Sudoku::Puzzle.new(ARGF.readlines))
>
> Can someone walk me through (baby-steps) how to actually "require"
> sudoku so that I can see the Module in action. The more explicit your
> answer the better since I am a newbee's newbee!
When you require() a file, ruby looks in some default directories for
the file. You can see which directories are searched by default like
this:
puts $LOAD_PATH
The default directoies that are displayed should also include the
current directory ("."), which is the directory specified in the prompt
next to which your typed the command to run your program:
some_dir/sub_dir> ruby my_program.rb
So if the file you are trying to include is in the current directory, or
one of the default directories, you can require() it.
If the file you are trying to require() is in some other directory, then
you need to either move it into the current directory or one of the
default directories; or you can tell ruby to also search the directory
which contains the file you are trying to require().
There are several ways to accomplish that:
1) Add the directory containing the file you want to require() to the
directories that are searched by default:
$LOAD_PATH << "/some_dir/sub_dir/my_ruby_programs/"
For a more permanent solution, you can also:
2) Add the directory containing the file you want to require, to your
system's PATH environment variable.
3) Create a new environment variable called RUBYPATH, which specifies
additional directories that you want ruby to search.
--
Posted via http://www.ruby-forum.com/.
[toc] | [prev] | [next] | [standalone]
| From | 7stud -- <bbxx789_05ss@yahoo.com> |
|---|---|
| Date | 2011-04-11 18:23 -0500 |
| Message-ID | <4a277f7435d09ffe2508e24ebe321c96@ruby-forum.com> |
| In reply to | #2641 |
7stud -- wrote in post #992150: > 1) Add the directory containing the file you want to require() to the > directories that are searched by default: > > $LOAD_PATH << "/some_dir/sub_dir/my_ruby_programs/" > $LOAD_PATH is an array, and the << is like calling push() on an array--for instance: arr.push(additional_element) The result is that the $LOAD_PATH array will contain an additional string, which is the name of the directory you want to add. However, the $LOAD_PATH array will be changed only for the duration of your program; when you run another program, the $LOAD_PATH array will be reconstructed with the default directories plus whatever directory is the current directory. > For a more permanent solution, you can also: > > 2) Add the directory containing the file you want to require, to your > system's PATH environment variable. > > 3) Create a new environment variable called RUBYPATH, which specifies > additional directories that you want ruby to search. > > -- Posted via http://www.ruby-forum.com/.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.ruby
csiph-web