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?
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?
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
I agree with Jamon. I created a config folder outside app directory and then added
app.files << Dir.glob("./config/*.rb")
to my Rakefile.