Created
April 9, 2010 20:02
-
-
Save jdlich/361529 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def initialize item | |
# set the item instance variable | |
@item = item | |
# grab the item's attributes from its yaml file | |
attributes = File.expand_path('content' + item.identifier.gsub(/\/$/,'') + '.yaml') | |
# load the yaml data into a hash and grab just the attribute | |
# names, not the values | |
attributes = File.open(attributes) { |a| YAML::load(a) }.keys | |
# create an instance variable and an accessor method for each | |
# attribute on the fly | |
attributes.each do |a| | |
instance_variable_set("@#{a}", item[a.to_sym]) | |
instance_eval %{ | |
def #{a} | |
instance_variable_get("@#{a}") | |
end | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment