life.i.think: Scripting CONSTANTS in environment.rb {rails}

Scripting CONSTANTS in environment.rb {rails}
Scribbled on March 26th. 0 comments.

You can script the declaration of constants easily enough with Module#const_set.

Sometimes you want to do this from environment.rb when you are loading the Rails stack. It’s not immediately clear which module this is encapsulated in. Turns out it’s not contained within anything specifically … just plain ol’ Object.


foo.each do |bar|
  Object.const_set("CONSTANTLY_#{bar.upcase}", 42)
end
Comments

Leave a response