4

I'd like to define global constants in RubyMotion. What is the best way to declare global constants?

If it's Rails, put global constants in config/initializers/constants.rb is common way, I think. Any alternative place in RubyMotion?

Naoyoshi Aikawa
  • 1,135
  • 10
  • 16

2 Answers2

6

There isn't a specific place to put them. I'd recommend creating a config folder and dropping your constants.rb file into that. Then, any constants you define in that file should be available to your classes.

# /app/config/constants.rb
THIS_IS_MY_CONSTANT = "Yep"

# /app/app_delegate.rb
class AppDelegate
  def application(app, didFinishLaunchingWithOptions: opt)
    puts THIS_IS_MY_CONSTANT # => "Yep"
  end
end
Jamon Holmgren
  • 23,738
  • 6
  • 59
  • 75
5

I agree with Jamon. I created a config folder outside app directory and then added

app.files << Dir.glob("./config/*.rb")

to my Rakefile.

RajeshT
  • 417
  • 4
  • 9