Class: Rattributes

Inherits:
Module
  • Object
show all
Defined in:
lib/rattributes.rb

Constant Summary collapse

VERSION =
'0.0.3'

Instance Method Summary collapse

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

#inspectObject 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