Skip to content

Instantly share code, notes, and snippets.

@wengzilla
Forked from styliii/shipping.rb
Created December 20, 2012 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wengzilla/4348913 to your computer and use it in GitHub Desktop.
Save wengzilla/4348913 to your computer and use it in GitHub Desktop.
require 'yaml'
file_data = YAML.load_file('shipping.yaml')
class ShippingData
def initialize(attr={})
@sd_data = attr
end
def sd_data
@sd_data
end
def method_missing(method_name, arg= nil)
method_name = arg unless arg.nil?
if @sd_data.respond_to?(method_name)
new_sd = ShippingData.new(@sd_data.send(method_name))
else
new_sd = ShippingData.new(@sd_data[method_name.to_s])
end
puts new_sd.sd_data if new_sd.sd_data.class == String
return new_sd
end
end
data = ShippingData.new(file_data)
data.product.first.sku
data["product"].first["sku"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment