Skip to content

Instantly share code, notes, and snippets.

@drobune
Created April 5, 2016 06:22
Show Gist options
  • Save drobune/d65f3addf906c2102a2b1806b616bb00 to your computer and use it in GitHub Desktop.
Save drobune/d65f3addf906c2102a2b1806b616bb00 to your computer and use it in GitHub Desktop.
hashを受け取ってアクセス可能なインスタンス変数を生成するクラス
class Gabagaba
def initialize(opts = {})
opts.each do |key, value|
self.class.class_eval { attr_accessor "#{key}" }
self.instance_variable_set "@#{key}" value
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment