Created
December 20, 2012 04:12
-
-
Save styliii/4342936 to your computer and use it in GitHub Desktop.
mock code interview example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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