Class: Imdb::Movie
- Inherits:
-
Object
- Object
- Imdb::Movie
- Defined in:
- lib/imdb/movie.rb
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Movie
constructor
Turn Any hash into attributes of a class.
Constructor Details
#initialize(attributes) ⇒ Movie
9 10 11 12 13 14 15 16 |
# File 'lib/imdb/movie.rb', line 9 def initialize(attributes) attributes.each do |k,v| k = k.downcase self.instance_variable_set("@#{k}", v) ## create and initialize an instance variable for this key/value pair self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) ## create the getter that returns the instance variable self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) ## create the setter that sets the instance variable end end |