Module: Juvet::Attributable

Included in:
Bot
Defined in:
lib/juvet/attributable.rb

Instance Method Summary collapse

Instance Method Details

#attribute!(attributes) ⇒ Object



12
13
14
15
# File 'lib/juvet/attributable.rb', line 12

def attribute!(attributes)
  (@_attributes ||= []).concat attributes.keys
  attributes.keys.each { |name| define_attribute! name }
end

#attributesObject



17
18
19
20
21
22
23
24
25
# File 'lib/juvet/attributable.rb', line 17

def attributes
  attributes = {}
  @_attributes.each do |attribute|
    if self.respond_to? attribute
      attributes[attribute] = self.send(attribute)
    end
  end
  attributes
end

#initialize(attributes = {}) ⇒ Object



3
4
5
6
# File 'lib/juvet/attributable.rb', line 3

def initialize(attributes={})
  initialize! attributes
  attribute! attributes
end

#initialize!(attributes) ⇒ Object



8
9
10
# File 'lib/juvet/attributable.rb', line 8

def initialize!(attributes)
  attributes.each { |name, value| set_variable! name, value }
end