Created
October 2, 2008 04:39
-
-
Save mattetti/14278 to your computer and use it in GitHub Desktop.
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
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