The best way to export data from one file and use it in another is either a class or a module.
Example:
# price.rb module InstancePrices PRICES = { 'us-east-1' => {'t1.micro' => 0.02, ... }, ... } end
In another file, you can require this. Using load is incorrect.
require 'price' InstancePrices::PRICES['us-east-1']
You can even shorten this using include :
require 'price' include InstancePrices PRICES['us-east-1']
What you did is a little hard to use. A proper object-oriented design will encapsulate this data in some class, and then provide an interface for this. Violation of your data directly contradicts these principles.
For example, you want the InstancePrices.price_for('t1.micro', 'us-east-1') method to return the correct price. By separating the internal structure used to store data from the interface, you avoid creating huge dependencies in your application.
source share