Skip to content

Instantly share code, notes, and snippets.

@romikoops
Created December 10, 2014 11:29
Show Gist options
  • Save romikoops/adceb5c090672bb9a5e1 to your computer and use it in GitHub Desktop.
Save romikoops/adceb5c090672bb9a5e1 to your computer and use it in GitHub Desktop.
Example of metaprogramming
class QuestionRow
def initialize(internal_id: nil, chapter: nil, position: nil, text: nil, images: nil, video: nil, explanation: nil,
error_points: nil, prerequisite_id: nil, external_id: nil, choices: nil)
method(__method__).parameters.each do |type, name|
if type == :key
instance_variable_set "@#{name}", eval("#{name}")
self.class.class_eval { attr_reader name}
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment