# I suspect syntax got me this time

**URL:** <https://www.ruby-forum.com/t/i-suspect-syntax-got-me-this-time/229180>\
**Category:** Ruby\
**Created:** [July 24, 2009, 6:54am UTC](https://www.ruby-forum.com/t/i-suspect-syntax-got-me-this-time/229180 "2009-07-24T06:54:05Z")\
**Posts on this page:** 3\
**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:54am UTC](https://www.ruby-forum.com/t/i-suspect-syntax-got-me-this-time/229180/1 "2009-07-24T06:54:05Z")

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

# 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 24, 2009, 8:49am UTC](https://www.ruby-forum.com/t/i-suspect-syntax-got-me-this-time/229180/2 "2009-07-24T08:49:12Z")

</div>

Venkat A. wrote:

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

I don’t know what all that code does–it’s a mess. Here is a simple  
example:

class A  
def A.get  
“hi”  
end  
end

class B  
def test  
puts A.get  
end  
end

b = B.new  
b.test

–output:–  
hi

---

<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, 5:07pm UTC](https://www.ruby-forum.com/t/i-suspect-syntax-got-me-this-time/229180/3 "2009-07-24T17:07:33Z")

</div>

Hi –

On Fri, 24 Jul 2009, Venkat A. wrote:

> end  
> require “webrick”  
> @@serialVersionUID = 1
> 
> # @xmlParser
> 
> # @htmlParsers
> 
> @hasXmlTemplate  
> @stcRead  
> @formatHashtable  
> @replaceHashtable

All of those instance variables are uninitialized. You just wrote  
this:

nil  
nil  
nil  
nil

So the first step would be to delete all of them.

> def initialize(connectionProvider)  
> Configurator.load\_xml\_file(file)
> 
> # if **FILE** == $0 && ARGV.length \< 1
> 
> # @i
> 
> # configureLog4r(nil)
> 
> # @strFile

Again, you’re just stating values (nil or otherwise). If you’re not  
assigning to a variable or doing something with its value, there is  
never any reason to type it.

I think you’ve got some ideas about declaring variables that perhaps  
come from your work in another language but that are not relevant to  
Ruby. The best thing would probably be to get hold of some learning  
materials and find out what instance variables actually are, and how  
they’re used. That will give you a foothold as you work further on  
your code.

David
