Sha256: 70f237c28a99ac665ecac6f5ff8a8f6f961e1053214700728a4e70b5ac56bc3b
Contents?: true
Size: 689 Bytes
Versions: 3
Compression:
Stored size: 689 Bytes
Contents
module Imdb class Movie ## # Turn Any hash into attributes of a class # # Imdb::Movie.new({:Title => "Darkwing Duck", :Year => "1991"}) # 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 end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
imdb_api-0.0.4 | lib/imdb/movie.rb |
imdb_api-0.0.3 | lib/imdb/movie.rb |
imdb_api-0.0.2 | lib/imdb/movie.rb |