Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to define global constants in RubyMotion?

Tags:

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?

like image 741
Naoyoshi Aikawa Avatar asked Dec 21 '22 05:12

Naoyoshi Aikawa


1 Answers

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
like image 60
Jamon Holmgren Avatar answered Feb 17 '23 00:02

Jamon Holmgren