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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With