Forum: Ruby Newbie Problem

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.
39efe61e290a99689262174e22d0a1e5?d=identicon&s=25 unknown (Guest)
on 2008-12-30 00:05
(Received via mailing list)
I'm trying to teach myself Ruby(and then rails) using Pragmatic's
"Programming Ruby" for the language part.  I get the following error
under NetBeans:

C:/Program Files/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/site_ruby/1.8/builtin/core_ext/symbol.rb:1:in
`const_missing': uninitialized constant Song (NameError)
        from C:\Projects\RubyLearning\RubyApplication1\lib\main.rb:4

when I try to run a two-file project built from the first example in
Chapter 3:

song.rb:
# Sample code from Programing Ruby, page 23
class Song
  def initialize(name, artist, duration)
    @name     = name
    @artist   = artist
    @duration = duration
  end
end

main.rb:
a_song = Song.new("Pie Jesu", "Sarah Brightman", "234")
song.inspect

Any suggestions or help much appreciated. Also suggestions for some
newbie-tolerant discussion forum.

Thanks in advance.
3637c8ab02ad27d4548614027d1d26f3?d=identicon&s=25 Scott Lillibridge (Guest)
on 2008-12-30 00:10
(Received via mailing list)
You have to require 'song.rb' in your main.rb file. Near the top of your
main.rb file place the following line (if they are both in the same
directory)
require 'song.rb'

Scott
8fa0f5c2bf8ad238baa4e20cb0360ebd?d=identicon&s=25 Matt Harrison (iwasinnamuknow)
on 2008-12-30 00:11
(Received via mailing list)
sehlat@berkeley.edu wrote:
> Chapter 3:
>
> main.rb:
> a_song = Song.new("Pie Jesu", "Sarah Brightman", "234")
> song.inspect

Have you require'd song.rb in you main.rb file?

It should look something like:


require 'song'

a_song = Song.new("Pie Jesu", "Sarah Brightman", "234")
song.inspect


HTH

Matt
39efe61e290a99689262174e22d0a1e5?d=identicon&s=25 unknown (Guest)
on 2008-12-30 01:35
(Received via mailing list)
Thank you. The require statement doesn't get mentioned until about
fifty pages farther on. :)


On Mon, 29 Dec 2008 18:09:47 -0500, Scott Lillibridge
1d53b088a989e069b94597c282eebbbc?d=identicon&s=25 Simon Krahnke (Guest)
on 2008-12-30 05:35
(Received via mailing list)
* <sehlat@berkeley.edu> (01:30) schrieb:

> Thank you. The require statement doesn't get mentioned until about
> fifty pages farther on. :)

The example doesn't talk about separate files. That's why it doesn't
mention require.

mfg,                         simon .... l
This topic is locked and can not be replied to.