Including problems

I have a file (index.rb) that includes head.rb. head.rb has a class
"Page" and in it, method "start". The problem is that when calling
Page.start I get this error: "uninitialized constant
#<Module:0x2a9e2793f8>::Page (NameError)" it is pretty frustrating, can
anyone tell me whats wrong with it?

If you are inside of another modules namespace, maybe you'd need to directly address the Page class you want. Otherwise, please try to cut down the code to a minimal example and post it here.

E.g.

::Page.new.start

hope to help,

Brian

···

On Mon, 21 Feb 2005 06:44:42 +0900 "T E" <thedcm@gmail.com> wrote:

I have a file (index.rb) that includes head.rb. head.rb has a class
"Page" and in it, method "start". The problem is that when calling
Page.start I get this error: "uninitialized constant
#<Module:0x2a9e2793f8>::Page (NameError)" it is pretty frustrating, can
anyone tell me whats wrong with it?

index.rb:

require 'head'

Page.start( 'Message Boards', 'Message Boards', nil )

head.rb:

(apache header stuff)
class Page
  def start( page_title = nil, page_header = nil, page_caption = nil )
    puts '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' +
    '<html xmlns="http://www.w3.org/1999/xhtml">' +
    '<head><title>', page_title, '</title></head>'
  end
end

T E wrote:

Page.start( 'Message Boards', 'Message Boards', nil )

This is sending the #start method to Page. In other words, it is calling a class method.

class Page
  def start( page_title = nil, page_header = nil, page_caption = nil )

This defines an _instance_ method of class Page. You can call #start on instances of Page, but not on Page itself.

Maybe what you want is

class Page
   def self.start(...)

That works, thanks :slight_smile: