Class: MeetupApi::Hashit
- Inherits:
-
Object
- Object
- MeetupApi::Hashit
- Defined in:
- lib/meetup_api.rb
Overview
Turns a hash into an object - see tinyurl.com/97dtjj
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(hash) ⇒ Hashit
constructor
A new instance of Hashit.
Constructor Details
#initialize(hash) ⇒ Hashit
Returns a new instance of Hashit.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/meetup_api.rb', line 80 def initialize(hash) hash.each do |k,v| # create and initialize an instance variable for this key/value pair self.instance_variable_set("@#{k}", v) # create the getter that returns the instance variable self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) # create the setter that sets the instance variable (disabled for readonly) ##self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) end end |