# I suspect syntax got me this time

**URL:** <https://rubytalk.org/t/i-suspect-syntax-got-me-this-time/54582>\
**Category:** ruby-talk\
**Created:** [24 July 2009 04:51 UTC](https://rubytalk.org/t/i-suspect-syntax-got-me-this-time/54582 "2009-07-24T04:51:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Venkat\_Akkineni](https://avatars.discourse-cdn.com/v4/letter/v/958977/32.png) [@Venkat\_Akkineni](https://rubytalk.org/u/Venkat_Akkineni)\
**Post date:** [24 July 2009 04:51 UTC](https://rubytalk.org/t/i-suspect-syntax-got-me-this-time/54582/1 "2009-07-24T04:51:55Z")

</div>

Hi

&nbsp;&nbsp;&nbsp;&nbsp;I have created a class with a class method. I am trying to call it  
from a different class and I get the "uninitialized constant" error.  
Could some body help me out.

> Class with class method

# To change this template, choose Tools | Templates  
# and open the template in the editor.

require "log4r/logger"

class XELogger \< Log4r::Logger

&nbsp;&nbsp;def XELogger.get(fullname)  
&nbsp;&nbsp;&nbsp;&nbsp;begin  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return self.superclass.get(fullname)  
&nbsp;&nbsp;&nbsp;&nbsp;rescue NameError  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return Log4r::Logger.new(fullname , nil , true , false)  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end

end

> Calling class

# To change this template, choose Tools | Templates  
# and open the template in the editor.

#require "rubygems"  
require "webrick"  
require "log4r"  
require "monitor"  
#require "XELogger"  
require "rexml/document"

class XmlEngine \< WEBrick::HTTPServlet::FileHandler

&nbsp;&nbsp;include MonitorMixin

&nbsp;&nbsp;# this is a BigNum  
&nbsp;&nbsp;@@serialVersionUID = 1

# @xmlParser  
# @htmlParsers  
&nbsp;&nbsp;@hasXmlTemplate  
&nbsp;&nbsp;@stcRead  
&nbsp;&nbsp;@formatHashtable  
&nbsp;&nbsp;@replaceHashtable  
# @strDriverDefault  
# @strUrlDefault  
# @strBaseLocation  
# @strFormatFile  
# @fileXmlEngineFormat  
# @fileBaseLocation  
# @sessionLanguage  
# @strReplaceWhat  
# @strReplaceWith  
# @isResource = false

# @configXMLEngine

# These loggers (xmlEngine and reloadXml) should be instantated before  
they can  
# used.

&nbsp;&nbsp;@@log4rXmlEngine = XELogger.get['xmlEngine']  
# @@log4rReloadXml = XELogger.get('reloadXml')

&nbsp;&nbsp;# Constructor  
&nbsp;&nbsp;# ToDo: Assign this argument to the instance variable  
"connectionProvider"  
&nbsp;&nbsp;def initialize(connectionProvider)  
&nbsp;&nbsp;&nbsp;&nbsp;init  
&nbsp;&nbsp;end

# ToDo: Needs testing  
&nbsp;&nbsp;private  
&nbsp;&nbsp;def loadParams  
&nbsp;&nbsp;&nbsp;&nbsp;@replaceHashtable = Hash.new # Hash with a string as key and Array  
as value

&nbsp;&nbsp;&nbsp;&nbsp;@htmlReplaceVector = Array.new # Array of ReplaceElement objects  
&nbsp;&nbsp;&nbsp;&nbsp;@htmlReplaceVector.push(ReplaceElement.new("&", "&amp;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\"", "&quot;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\n", " ")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\r", " ")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\<", "&lt;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\>", "&gt;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new( "®", "&reg;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new( "€", "&euro;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new( "ñ", "&ntilde;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new( "Ñ", "&Ntilde;"))  
&nbsp;&nbsp;&nbsp;&nbsp;@replaceHashtable[:html] = @htmlReplaceVector

&nbsp;&nbsp;&nbsp;&nbsp;@foReplaceVector = Array.new  
&nbsp;&nbsp;&nbsp;&nbsp;@foReplacement.push(ReplaceElement.new("&", "&#38;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\<", "&#60;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\>", "&#62;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\\", "&#92")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("º", "&#186")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("ª", "&#170")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("®", "&#174;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("€", "&#8364;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\n", "&#10;"))  
&nbsp;&nbsp;&nbsp;&nbsp;@replaceHashtable[:fo] = @foReplaceVector

&nbsp;&nbsp;&nbsp;&nbsp;@htmlPreformattedReplaceVector = Array.new  
&nbsp;&nbsp;&nbsp;&nbsp;@htmlPreformattedReplaceVector.push(ReplaceElement.new("&",  
"&amp;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\"", "&quot;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\<", "&lt;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\>", "&gt;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\n", "\<BR\>")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\r", " ")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("®", "&reg;"))  
&nbsp;&nbsp;&nbsp;&nbsp;@replaceHashtable[:htmlPreformatted] = @htmlPreformattedVector

&nbsp;&nbsp;&nbsp;&nbsp;@htmlHelpReplaceVector = Array.new  
&nbsp;&nbsp;&nbsp;&nbsp;@htmlHelpReplaceVector.push(ReplaceElement.new("\n", "\<BR\>")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement("\r", ""))  
&nbsp;&nbsp;&nbsp;&nbsp;@replaceHashtable[:htmlHelp] = @htmlHelpReplaceVector

&nbsp;&nbsp;&nbsp;&nbsp;@htmlPreformattedTextareaReplaceVector = Array.new  
&nbsp;&nbsp;&nbsp;&nbsp;@htmlPreformattedTextareaReplaceVector.push(ReplaceElement.new("&",  
"&amp;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\"", "&quot;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\<", "&lt;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("\>", "&gt;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement.new("®", "&reg;"))  
&nbsp;&nbsp;&nbsp;&nbsp;@replaceHashtable[:htmlPreformattedTextarea] =  
@htmlPreformattedTextareaReplaceVector

&nbsp;&nbsp;&nbsp;&nbsp;@htmlJavascriptReplaceVector = Array.new  
&nbsp;&nbsp;&nbsp;&nbsp;@htmlJavascriptReplaceVector.push(ReplaceElement.new("'", "\\'")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement("\"", "&quot;")).  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(ReplaceElement("\n", "\\n"))  
&nbsp;&nbsp;&nbsp;&nbsp;@replaceHashtable[:htmlJavascript] = @htmlJavascriptReplaceVector

&nbsp;&nbsp;end

&nbsp;&nbsp;# Simili to Java Servlet's lifecycle method init.  
&nbsp;&nbsp;public  
&nbsp;&nbsp;def init()  
&nbsp;&nbsp;&nbsp;&nbsp;@hasXmlTemplate = Hash.new # Vector of XmlTemplates  
&nbsp;&nbsp;&nbsp;&nbsp;@stcRead = Stack.new # Stack of Xml Templates not Read  
&nbsp;&nbsp;&nbsp;&nbsp;@formatHashtable = Hash.new # Hash table with String as key and  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# FormatCouple as value  
&nbsp;&nbsp;&nbsp;&nbsp;# ToDo instantiate XmlParser  
# @xmlParserFormat =

&nbsp;&nbsp;end

&nbsp;&nbsp;# This mesage reads a file that defines a XmlTemplate without any  
discard  
&nbsp;&nbsp;def readXmlTemplate(strXmlTemplateFile)

&nbsp;&nbsp;end

&nbsp;&nbsp;# This function reads a file that defines a XmlTemplate with a vector  
of  
&nbsp;&nbsp;# discard  
&nbsp;&nbsp;def readXmlTemplate(strXmlTemplateFile, \*discard)  
&nbsp;&nbsp;&nbsp;&nbsp;# synchronize {put the code to be synchronized here}  
&nbsp;&nbsp;end

&nbsp;&nbsp;# This function adds the xmltemplate to the list of xmltemplates and  
read all  
&nbsp;&nbsp;# the XmlTemplates.  
&nbsp;&nbsp;def readAllXmlTemplates(strXmlTemplateName, strXmlTemplateFile,  
\*discard)

&nbsp;&nbsp;end

&nbsp;&nbsp;# This function add the XmlTemplate to the list of XmlTemplates or  
return an  
&nbsp;&nbsp;# existing XmlTemplate if it was found in the list.  
&nbsp;&nbsp;private  
&nbsp;&nbsp;def addXmlTemplate(strXmlTemplateName, strXmlTemplateFile, \*discard)

&nbsp;&nbsp;end

&nbsp;&nbsp;# This function reads the XmlTemplate  
&nbsp;&nbsp;def readFile(xmlTemplate)

&nbsp;&nbsp;end

&nbsp;&nbsp;public  
&nbsp;&nbsp;def do\_GET(request,response)  
&nbsp;&nbsp;&nbsp;&nbsp;puts "here in do\_get"  
&nbsp;&nbsp;end

&nbsp;&nbsp;def do\_POST(request,response)  
&nbsp;&nbsp;&nbsp;&nbsp;puts "here in do\_post"  
&nbsp;&nbsp;end

&nbsp;&nbsp;def connect

&nbsp;&nbsp;end

&nbsp;&nbsp;def closeConnections

&nbsp;&nbsp;end

&nbsp;&nbsp;def destroy

&nbsp;&nbsp;end

&nbsp;&nbsp;# Will configure log4r from the xml configure file passed  
&nbsp;&nbsp;# The file object can be just the name of the file if the  
&nbsp;&nbsp;# file is in the same folder, if otherwise file object  
&nbsp;&nbsp;# should be a complete path to file's location.  
&nbsp;&nbsp;# ToDo: Needs Tesing.  
&nbsp;&nbsp;def self.configureLog4r(file)  
&nbsp;&nbsp;&nbsp;&nbsp;if file !=nil  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Configurator.load\_xml\_file(file)  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Configurator.load\_xml\_file(log4r.xml)  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end

# Courtesy of:  
[http://rubynugs.blogspot.com/2006/12/creating-java-like-main-method-in-ruby.html](http://rubynugs.blogspot.com/2006/12/creating-java-like-main-method-in-ruby.html)

# do  
# if \_\_FILE\_\_ == $0 && ARGV.length \< 1  
# @i  
# configureLog4r(nil)  
# @strFile

> **···**
>
> #  
> # puts "main"  
> #  
> # else if \_\_FILE\_\_ == $0 && ARGV.length \> 1  
> #  
> #  
> # end  
> #  
> # end
> 
> &nbsp;&nbsp;# XmlEngineNP: classes for compatibilizing with the Reports version  
> &nbsp;&nbsp;def readReportConfiguration(strReportFile)
> 
> &nbsp;&nbsp;end
> 
> &nbsp;&nbsp;def readReportConfiguration(strReportFile, \*discard)
> 
> &nbsp;&nbsp;end
> 
> # # Log4r::Logger's get method throws a NameError when it cannot find  
> the  
> # # specified log file. This method will help create a new log file  
> when  
> # # one doesn't exist. ToDo: Create a subclass of Logger class and  
> override  
> # # the Logger class's get method.  
> # def fetchLogger(\_name)  
> # begin  
> # return @newLogFile = Log4r::Logger.get(\_name)  
> # rescue NameError  
> # return @newLogFile = Log4r::Logger.new(\_name , nil , true ,  
> false)  
> # end  
> # end
> 
> end  
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [25 July 2009 13:08 UTC](https://rubytalk.org/t/i-suspect-syntax-got-me-this-time/54582/2 "2009-07-25T13:08:44Z")

</div>

Venkat Akkineni wrote:

> &nbsp;&nbsp;&nbsp;&nbsp;I have created a class with a class method. I am trying to call it  
> from a different class and I get the "uninitialized constant" error.

You need to show the \*exact\* error message you get, and point out which  
line of the source this corresponds to. Posting hundreds of lines of  
irrelevant source is not a good idea. Keep removing lines until you have  
a 10-line program which still has the problem.

> # To change this template, choose Tools | Templates  
> # and open the template in the editor.
> 
> #require "rubygems"  
> require "webrick"  
> require "log4r"  
> require "monitor"  
> #require "XELogger"  
> require "rexml/document"

You commented out 'require "XELogger"' above. So if the constant (class)  
XELogger is defined in that file, and the error message is saying that  
constant XELogger is unknown, why are you surprised?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
