Sha256: 6e070c077722fb49e42e9f2fc5bd19a0e5dcc60dcaae3486763904f115365286
Contents?: true
Size: 691 Bytes
Versions: 2
Compression:
Stored size: 691 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
imdb_api-0.0.6 | lib/imdb/movie.rb |
imdb_api-0.0.5 | lib/imdb/movie.rb |