From the ruby book install on win32

Hi folks,

Though i'd give ruby a try :slight_smile:

from the book you get when installing ruby 1.8.6 about the program Song.

this is the code i pasted into SciTE.

class Song
  def initialize(name, artist, duration)
    @name = name
    @artist = artist
    @duration = duration
  end
end

this i saved as Song.rb
In the output window i type ruby aSong.rb
and get
ruby aSong.rb

ruby aSong.rb

ruby: No such file or directory -- aSong.rb (LoadError)

Exit code: 1

and with parameters i get

ruby aSong.rb("me Myself and I"," we are sailing",180)

ruby: No such file or directory -- aSong.rb(me Myself and I, we are
sailing,180) (LoadError)

Exit code: 1

I was expecting it to drop back to the prompt without giving an error.

anyone explain to me what i'm not doing right?

I'm playing at present and would like to go through a worked example
tutorial of say a name address app where you...
1. You punch in the data and it spits out to screen.
2. Take that and get user input from screen and dump to screen.
3. Take user input and output to text file.
4. Take user input and allow data to be edited and then written to file

all this as a cmd line app (don't want to get too greedy and bog myself
down with gui stuff or web stuff yet! (not done any cgi or web dev at
all)

Also note i understand OOp but in the past theory and practical work has
left me with a big hole that i've not been able to cross.

anyhow wait for comments

dave.

路路路

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

You saved the file as "Song.rb" and you're trying to run a file named
"aSong.rb". Do you *seriously* not understand what you're doing wrong?

路路路

On 6/22/07, Dave Lilley <dglnz@yahoo.com> wrote:

this i saved as Song.rb
In the output window i type ruby aSong.rb
and get
ruby aSong.rb
>ruby aSong.rb
ruby: No such file or directory -- aSong.rb (LoadError)
>Exit code: 1

Bugger!!!

talk about looking like a f00l :slight_smile:

saved code below as Song.rb

class Song
  def initialize(name, artist, duration)
    @name = name
    @artist = artist
    @duration = duration
  end
end

tried it with Song.rb and got this

     ruby Song.rb

     >ruby Song.rb
     >Exit code: 0

Which i would expect to be something that's worked as expected.
Now if i pass parameters to it as in

     ruby Song.rb("here","come frank",60)
     >ruby Song.rb("here","come frank",60)
     ruby: No such file or directory -- Song.rb(here,come frank,60)
(LoadError)
     >Exit code: 1

so i expect this is where the error is the parameters aren't know to the
program
and i get the LoadError.

Lyle could you confirm this to me?

I'm trying to copy from the ruby book that comes with ruby 1.8.6 win32.

thanks for the well enlightened response. Wasn't trying to be silly, but
was a bit tried (in my defense) :).

dave.

Lyle Johnson wrote:

路路路

On 6/22/07, Dave Lilley <dglnz@yahoo.com> wrote:

this i saved as Song.rb
In the output window i type ruby aSong.rb
and get
ruby aSong.rb
>ruby aSong.rb
ruby: No such file or directory -- aSong.rb (LoadError)
>Exit code: 1

You saved the file as "Song.rb" and you're trying to run a file named
"aSong.rb". Do you *seriously* not understand what you're doing wrong?

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

Right. When you say "the Ruby book that comes with Ruby 1.8.6 win32", I'm going to assume you're talking about "Programming Ruby" (a.k.a. the Pickaxe book).

Now that you've created the Song class, you want to test it by creating a new Song instance. To do that, add this line to the end of your program (Song.rb), after the class definition:

  aSong = Song.new("here", "come frank", 60)

In the Pickaxe book, there's a similar example that uses the song "Bicyclops" by Bela Fleck. Now, the discussion in the Pickaxe book doesn't make this point very clear, but for you to actually see any output from this program, you're going to need to add at least one more line:

  puts aSong.inspect

So the entire contents of the file Song.rb should now look something like this:

  class Song
    def initialize(name, artist, duration)
      @name = name
      @artist = artist
      @duration = duration
    end
  end

  aSong = Song.new("here", "come frank", 60)
  puts aSong.inspect

Now if you run this at the command prompt by typing:

  ruby Song.rb

You should see some output like this:

  #<Song:0x52c970 @duration=60, @name="here", @artist="come frank">

Hope this helps,

Lyle

路路路

On Jun 22, 2007, at 11:38 PM, Dave Lilley wrote:

Now if i pass parameters to it as in

     ruby Song.rb("here","come frank",60)

ruby Song.rb("here","come frank",60)

     ruby: No such file or directory -- Song.rb(here,come frank,60)
(LoadError)

Exit code: 1

so i expect this is where the error is the parameters aren't know to the
program
and i get the LoadError.

Relax these things happen all the time, I remember debugging a file
three hours, getting completely crazy, doubting all save...
... that I was editing the file remotely and running the tests locally...
Great feature of vim allowing to edit files remotely :wink:

Cheers
Robert
P.S.
One could of course also drink less, but is this a reasonable option ?
R.

路路路

On 6/23/07, Dave Lilley <dglnz@yahoo.com> wrote:

Bugger!!!

talk about looking like a f00l :slight_smile:

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

Lyle Johnson wrote:

program
and i get the LoadError.

Right. When you say "the Ruby book that comes with Ruby 1.8.6 win32",
I'm going to assume you're talking about "Programming Ruby" (a.k.a.
the Pickaxe book).

You are correct. Also i know that this was the first edition so i
thought maybe there was some differences between the version of ruby it
was realsed for and this current release.

Now that you've created the Song class, you want to test it by
creating a new Song instance. To do that, add this line to the end of
your program (Song.rb), after the class definition:

  aSong = Song.new("here", "come frank", 60)

In the Pickaxe book, there's a similar example that uses the song
"Bicyclops" by Bela Fleck. Now, the discussion in the Pickaxe book
doesn't make this point very clear, but for you to actually see any
output from this program, you're going to need to add at least one
more line:

  puts aSong.inspect

Never thought of this as a problem!
as always it's the simple things you over look that cause the problems.

So the entire contents of the file Song.rb should now look something
like this:

  class Song
    def initialize(name, artist, duration)
      @name = name
      @artist = artist
      @duration = duration
    end
  end

  aSong = Song.new("here", "come frank", 60)
  puts aSong.inspect

Now if you run this at the command prompt by typing:

  ruby Song.rb

You should see some output like this:

  #<Song:0x52c970 @duration=60, @name="here", @artist="come frank">

Hope this helps,

Lyle

visited the ruby online tutorial last night and found it great!!
but i am wondering why when i tried doing something from either the
pickaxe book or a online pdf the interactive shell wouldn't allow me to
do the same things!

one was to create a def (still i'll check this out better another
night).

thanks for the help so far and in the famous words of arnie I'll be
back!

dave.

路路路

On Jun 22, 2007, at 11:38 PM, Dave Lilley wrote:

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