# Constant redefinition warning

**URL:** <https://www.ruby-forum.com/t/constant-redefinition-warning/159113>\
**Category:** Rails\
**Created:** [January 31, 2009, 7:44pm UTC](https://www.ruby-forum.com/t/constant-redefinition-warning/159113 "2009-01-31T19:44:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [January 31, 2009, 7:44pm UTC](https://www.ruby-forum.com/t/constant-redefinition-warning/159113/1 "2009-01-31T19:44:37Z")

</div>

I get a redefinition warning :

log warning =\>  
/Users/myself/Developpement/MyApp/vendor/plugins/globalize2/lib/myapp/  
validations.rb:18: warning: already initialized constant  
RoleTranslation

I am using the following code, apps is running well w warning  
module Validations  
def validate\_translation\_uniqueness\_of(\*attr\_names)  
translation\_class = Object.const\_set “#{self.class.name}Translation”,  
Class.new(::ActiveRecord::Base){}  
…

I tried now to avoid it writing :  
translation\_class = Object.const\_set “#{self.class.name}Translation”,  
Class.new(::ActiveRecord::Base){} unless defined?("#{self.class.name}  
Translation")  
but it fails … (obviously don’t like a string…)

I also tried:  
translation\_class = Object.const\_set “#{self.class.name}Translation”,  
Class.new(::ActiveRecord::Base){} unless defined?("#{self.class.name}  
Translation".to\_sym)

“#{self.class.name}Translation”.to\_sym =\> :AccountingPeriodTranslation  
which is also bad…

I need to have : #{self.class.name}Translation giving a class , how  
should I write it ?

defined?(AccountingPeriodTranslation) =\>“constant” is what I should  
test (or any other xxxxTranslation class where xxxx is self.class

thanks for your help

erwin

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [January 31, 2009, 11:29pm UTC](https://www.ruby-forum.com/t/constant-redefinition-warning/159113/2 "2009-01-31T23:29:19Z")

</div>

I changed the creation + test to a simple get constant as it’s already  
declared (being an ActiveRecord class created by Globalize plugin)

a simple :

globalize\_class = Object.const\_get “#{self.class.name}Translation”

gives me the class…
