Class: Mumble::Model
- Inherits:
-
Object
- Object
- Mumble::Model
- Extended by:
- Forwardable
- Defined in:
- lib/mumble-ruby/model.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(client, data) ⇒ Model
constructor
A new instance of Model.
- #inspect ⇒ Object
- #update(data) ⇒ Object
Constructor Details
#initialize(client, data) ⇒ Model
Returns a new instance of Model.
24 25 26 27 |
# File 'lib/mumble-ruby/model.rb', line 24 def initialize(client, data) @client = client @data = data end |
Class Method Details
.attribute(name, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mumble-ruby/model.rb', line 8 def attribute(name, &block) attributes << name define_method(name) do if block_given? self.instance_eval(&block) else @data[name.to_s] end end end |
.attributes ⇒ Object
19 20 21 |
# File 'lib/mumble-ruby/model.rb', line 19 def attributes @attributes ||= [] end |
Instance Method Details
#inspect ⇒ Object
33 34 35 36 37 38 |
# File 'lib/mumble-ruby/model.rb', line 33 def inspect attrs = self.class.attributes.map do |attr| [attr, send(attr)].join("=") end.join(" ") %Q{#<#{self.class.name} #{attrs}>} end |
#update(data) ⇒ Object
29 30 31 |
# File 'lib/mumble-ruby/model.rb', line 29 def update(data) @data.merge!(data) end |