Class: Rattributes
- Inherits:
-
Module
- Object
- Module
- Rattributes
- Defined in:
- lib/rattributes.rb
Constant Summary collapse
- VERSION =
'0.0.3'
Instance Method Summary collapse
-
#initialize(*attributes) ⇒ Rattributes
constructor
A new instance of Rattributes.
- #inspect ⇒ Object (also: #to_s)
Constructor Details
#initialize(*attributes) ⇒ Rattributes
Returns a new instance of Rattributes.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rattributes.rb', line 5 def initialize(*attributes) @attributes = attributes super() do define_singleton_method :included do |other| other.class_eval do attr_reader *attributes end end define_method :initialize do |data| attributes.each do |attribute| instance_variable_set("@#{attribute}", data[attribute]) end end end end |
Instance Method Details
#inspect ⇒ Object Also known as: to_s
24 25 26 |
# File 'lib/rattributes.rb', line 24 def inspect "#{self.class.to_s}(#{@attributes.map(&:inspect).join(', ')})" end |