Sha256: aa2c69e87a269fa62816ede33fd280b67f304789844f53d1f85ff826721208e2

Contents?: true

Size: 687 Bytes

Versions: 2

Compression:

Stored size: 687 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.1 lib/imdb/movie.rb
imdb_api-0.0.0 lib/imdb/movie.rb