Running file from command line issue

Hello. This is my first post and I'm new to coding and ruby. I'm
trying to learn the basics right now from Lynda.com. I'm trying to run
the above file "methods.rb" from the command line. In the command prompt
I navigate to the correct folder, switch to irb, and then I use

require"methods.rb".

In the lynda tutorial video, this returns >true. It works.

When I do it, I get

LoadError: cannot load such file -- methods.rb
   from
C:/Ruby200/lob/ruby/2.0/rubygems/core_ext/kernel_require.rb:45:in
'require'
   from
C:/Ruby200/lob/ruby/2.0/rubygems/core_ext/kernel_require.rb:45:in
'require'
   from (irb):2
   from C:/Ruby200/bin/irb:12:in '<main>'

This tutorial I'm watching is about four years old, so he's using an
older version of ruby. I know this is probably the simplest thing, but
as a newbie I have zero decoding skill. Any help would be appreciated.

Lastly, if you know of a better way to start learning ruby than the
lynda tutorail series, I'm very open to input of any kind.

Thanks in advance,
-S.

Attachments:
http://www.ruby-forum.com/attachment/8351/methods.rb

···

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

Hello. This is my first post and I'm new to coding and ruby. I'm
trying to learn the basics right now from Lynda.com. I'm trying to run
the above file "methods.rb" from the command line. In the command prompt
I navigate to the correct folder, switch to irb, and then I use
>require"methods.rb".

In the lynda tutorial video, this returns >true. It works.

When I do it, I get

LoadError: cannot load such file -- methods.rb
   from
C:/Ruby200/lob/ruby/2.0/rubygems/core_ext/kernel_require.rb:45:in
'require'
   from
C:/Ruby200/lob/ruby/2.0/rubygems/core_ext/kernel_require.rb:45:in
'require'
   from (irb):2
   from C:/Ruby200/bin/irb:12:in '<main>'

This tutorial I'm watching is about four years old, so he's using an
older version of ruby. I know this is probably the simplest thing, but
as a newbie I have zero decoding skill. Any help would be appreciated.

I think that's it. Ruby from 1.9.2 on does not allow you to `require` files
in the current working directory, unless you add that directory to
$LOAD_PATH; earlier versions automatically put it there for you. The
easiest way around that is to use `require_relative`.

I don't know what the Lynda tutorial does with code that you've required,
but if you just want to run a Ruby file from Windows's cmd, you can just
run `ruby methods.rb`. That's a little more direct, but it puts you back in
cmd when it finishes.

···

On Wed, Apr 17, 2013 at 8:46 PM, Gouverneur Cadwalader <lists@ruby-forum.com > wrote:

Lastly, if you know of a better way to start learning ruby than the
lynda tutorail series, I'm very open to input of any kind.

Thanks in advance,
-S.

When you require a file, it looks through an array of directories (called
the $LOAD_PATH) until it finds that file. In older rubies, the current
directory (represented with a period) was in the load path, in newer
rubies, it was removed.

The simple solution to your problem, in IRB, is to run irb like this `irb
-I .` (that's a capitol "i") which will add the current working directory
back into the load path, like it is on the Lynda.com version.

When you get to writing programs that depend on this, you can use
require_relative instead of require. When you get to writing real programs,
you'll need to learn and understand the load path. When you get that far,
read the section about the load path from here

-Josh

···

On Wed, Apr 17, 2013 at 8:46 PM, Gouverneur Cadwalader <lists@ruby-forum.com > wrote:

Hello. This is my first post and I'm new to coding and ruby. I'm
trying to learn the basics right now from Lynda.com. I'm trying to run
the above file "methods.rb" from the command line. In the command prompt
I navigate to the correct folder, switch to irb, and then I use
>require"methods.rb".

In the lynda tutorial video, this returns >true. It works.

When I do it, I get

LoadError: cannot load such file -- methods.rb
   from
C:/Ruby200/lob/ruby/2.0/rubygems/core_ext/kernel_require.rb:45:in
'require'
   from
C:/Ruby200/lob/ruby/2.0/rubygems/core_ext/kernel_require.rb:45:in
'require'
   from (irb):2
   from C:/Ruby200/bin/irb:12:in '<main>'

This tutorial I'm watching is about four years old, so he's using an
older version of ruby. I know this is probably the simplest thing, but
as a newbie I have zero decoding skill. Any help would be appreciated.

Lastly, if you know of a better way to start learning ruby than the
lynda tutorail series, I'm very open to input of any kind.

Thanks in advance,
-S.

Attachments:
http://www.ruby-forum.com/attachment/8351/methods.rb

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