Skip to content

Instantly share code, notes, and snippets.

@mattetti
Created October 2, 2008 04:39
Show Gist options
  • Save mattetti/14278 to your computer and use it in GitHub Desktop.
Save mattetti/14278 to your computer and use it in GitHub Desktop.
class Question
attr_accessor :node
@@accessors = [:type, :position, :text, :required_answers_count, :possible_answers, :hint]
def initialize (keys = {})
@node = {}
@node['questions']
keys.each do |k,v|
@node[k.to_s] = v if @@accessors.include?(k)
end
end
def to_s
@node
end
# create a getter and setter for each accessor define
@@accessors.each do |acc|
meth = acc.to_s
class_eval <<-RUBY
def #{meth}
node["#{meth}"]
end
def #{meth}=(value)
node["#{meth}"] = value
end
RUBY
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment