Forum: Ruby from the ruby book install on win32

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dave L. (Guest)
on 2007-06-22 13:12
Hi folks,

Though i'd give ruby a try :)

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.
Lyle J. (Guest)
on 2007-06-22 15:06
(Received via mailing list)
On 6/22/07, Dave L. <removed_email_address@domain.invalid> 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?
Dave L. (Guest)
on 2007-06-23 08:38
Bugger!!!

talk about looking like a f00l :)

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 J. wrote:
> On 6/22/07, Dave L. <removed_email_address@domain.invalid> 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?
Lyle J. (Guest)
on 2007-06-23 18:45
(Received via mailing list)
On Jun 22, 2007, at 11:38 PM, Dave L. 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).

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
Robert D. (Guest)
on 2007-06-23 19:14
(Received via mailing list)
On 6/23/07, Dave L. <removed_email_address@domain.invalid> wrote:
> Bugger!!!
>
> talk about looking like a f00l :)
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 ;)

Cheers
Robert
P.S.
One could of course also drink less, but is this a reasonable option ?
R.
Dave L. (Guest)
on 2007-06-24 13:22
Lyle J. wrote:
> On Jun 22, 2007, at 11:38 PM, Dave L. 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.
This topic is locked and can not be replied to.