[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Including problems

thedcm

2/20/2005 9:40:00 PM

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?

4 Answers

Brian Schröder

2/20/2005 10:21:00 PM

0

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?
>
>

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


thedcm

2/20/2005 10:30:00 PM

0

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

Joel VanderWerf

2/20/2005 11:00:00 PM

0

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(...)


thedcm

2/20/2005 11:11:00 PM

0

That works, thanks :)