# I suspect syntax got me this time

**URL:** <https://www.ruby-forum.com/t/i-suspect-syntax-got-me-this-time/226042>\
**Category:** Ruby\
**Created:** [July 24, 2009, 6:53am UTC](https://www.ruby-forum.com/t/i-suspect-syntax-got-me-this-time/226042 "2009-07-24T06:53:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![spinhoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/958977/32.png) [@spinhoo](https://www.ruby-forum.com/u/spinhoo)\
**Post date:** [July 24, 2009, 6:53am UTC](https://www.ruby-forum.com/t/i-suspect-syntax-got-me-this-time/226042/1 "2009-07-24T06:53:30Z")

</div>

Hi

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

def XELogger.get(fullname)  
begin  
return self.superclass.get(fullname)  
rescue NameError  
return Log4r::Logger.new(fullname , nil , true , false)  
end  
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

include MonitorMixin

# this is a BigNum

@@serialVersionUID = 1

# @xmlParser

# @htmlParsers

@hasXmlTemplate  
@stcRead  
@formatHashtable  
@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.

@@log4rXmlEngine = XELogger.get[‘xmlEngine’]

# @@log4rReloadXml = XELogger.get(‘reloadXml’)

# Constructor

# ToDo: Assign this argument to the instance variable

“connectionProvider”  
def initialize(connectionProvider)  
init  
end

# ToDo: Needs testing

private  
def loadParams  
@replaceHashtable = Hash.new # Hash with a string as key and Array  
as value

```
@htmlReplaceVector = Array.new # Array of ReplaceElement objects
@htmlReplaceVector.push(ReplaceElement.new("&", "&amp;")).
  push(ReplaceElement.new("\"", "&quot;")).
  push(ReplaceElement.new("\n", " ")).
  push(ReplaceElement.new("\r", " ")).
  push(ReplaceElement.new("<", "&lt;")).
  push(ReplaceElement.new(">", "&gt;")).
  push(ReplaceElement.new( "Â®", "&reg;")).
    push(ReplaceElement.new( "â‚¬", "&euro;")).
      push(ReplaceElement.new( "Ã±", "&ntilde;")).
      push(ReplaceElement.new( "Ã‘", "&Ntilde;"))
@replaceHashtable[:html] = @htmlReplaceVector

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

@htmlPreformattedReplaceVector = Array.new
@htmlPreformattedReplaceVector.push(ReplaceElement.new("&",

```

“&”)).  
push(ReplaceElement.new(“"”, “"”)).  
push(ReplaceElement.new(“\<”, “\<”)).  
push(ReplaceElement.new(“\>”, “\>”)).  
push(ReplaceElement.new(“\n”, “  
”)).  
push(ReplaceElement.new(“\r”, " ")).  
push(ReplaceElement.new(“Â®”, “®”))  
@replaceHashtable[:htmlPreformatted] = @htmlPreformattedVector

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

@htmlPreformattedTextareaReplaceVector = Array.new
@htmlPreformattedTextareaReplaceVector.push(ReplaceElement.new("&",

```

“&”)).  
push(ReplaceElement.new(“"”, “"”)).  
push(ReplaceElement.new(“\<”, “\<”)).  
push(ReplaceElement.new(“\>”, “\>”)).  
push(ReplaceElement.new(“Â®”, “®”))  
@replaceHashtable[:htmlPreformattedTextarea] =  
@htmlPreformattedTextareaReplaceVector

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

```

end

# Simili to Java Servlet’s lifecycle method init.

public  
def init()  
@hasXmlTemplate = Hash.new # Vector of XmlTemplates  
@stcRead = Stack.new # Stack of Xml Templates not Read  
@formatHashtable = Hash.new # Hash table with String as key and  
# FormatCouple as value  
# ToDo instantiate XmlParser

# @xmlParserFormat =

end

# This mesage reads a file that defines a XmlTemplate without any

discard  
def readXmlTemplate(strXmlTemplateFile)

end

# This function reads a file that defines a XmlTemplate with a vector

of

# discard

def readXmlTemplate(strXmlTemplateFile, \*discard)  
# synchronize {put the code to be synchronized here}  
end

# This function adds the xmltemplate to the list of xmltemplates and

read all

# the XmlTemplates.

def readAllXmlTemplates(strXmlTemplateName, strXmlTemplateFile,  
\*discard)

end

# This function add the XmlTemplate to the list of XmlTemplates or

return an

# existing XmlTemplate if it was found in the list.

private  
def addXmlTemplate(strXmlTemplateName, strXmlTemplateFile, \*discard)

end

# This function reads the XmlTemplate

def readFile(xmlTemplate)

end

public  
def do\_GET(request,response)  
puts “here in do\_get”  
end

def do\_POST(request,response)  
puts “here in do\_post”  
end

def connect

end

def closeConnections

end

def destroy

end

# Will configure log4r from the xml configure file passed

# The file object can be just the name of the file if the

# file is in the same folder, if otherwise file object

# should be a complete path to file’s location.

# ToDo: Needs Tesing.

def self.configureLog4r(file)  
if file !=nil  
Configurator.load\_xml\_file(file)  
else  
Configurator.load\_xml\_file(log4r.xml)  
end  
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

# XmlEngineNP: classes for compatibilizing with the Reports version

def readReportConfiguration(strReportFile)

end

def readReportConfiguration(strReportFile, \*discard)

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

---

<div class="post-metadata">

**Author:** ![spinhoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/958977/32.png) [@spinhoo](https://www.ruby-forum.com/u/spinhoo)\
**Post date:** [July 25, 2009, 3:08pm UTC](https://www.ruby-forum.com/t/i-suspect-syntax-got-me-this-time/226042/2 "2009-07-25T15:08:42Z")

</div>

Venkat A. wrote:

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