Class: Flattr::Base
- Inherits:
-
Object
- Object
- Flattr::Base
- Defined in:
- lib/flattr/base.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
(also: #to_hash)
Returns the value of attribute attrs.
Class Method Summary collapse
-
.lazy_attr_reader(*attrs) ⇒ Object
Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key.
- .lazy_attr_writer(*attrs) ⇒ Object
Instance Method Summary collapse
-
#[](method) ⇒ Object
Initializes a new Base object.
-
#initialize(attrs = {}) ⇒ Flattr::Base
constructor
Initializes a new Base object.
Constructor Details
#initialize(attrs = {}) ⇒ Flattr::Base
Initializes a new Base object
41 42 43 |
# File 'lib/flattr/base.rb', line 41 def initialize(attrs={}) @attrs = attrs.dup end |
Instance Attribute Details
#attrs ⇒ Object Also known as: to_hash
Returns the value of attribute attrs.
4 5 6 |
# File 'lib/flattr/base.rb', line 4 def attrs @attrs end |
Class Method Details
.self.lazy_attr_reader(attr) ⇒ Object .self.lazy_attr_reader(attrs) ⇒ Object
Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
13 14 15 16 17 18 19 20 21 |
# File 'lib/flattr/base.rb', line 13 def self.lazy_attr_reader(*attrs) attrs.each do |attribute| class_eval do define_method attribute do @attrs[attribute.to_s] end end end end |
.lazy_attr_writer(*attrs) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/flattr/base.rb', line 23 def self.lazy_attr_writer(*attrs) attrs.each do |attribute| class_eval do define_method "#{attribute}=" do |a| if @attrs[attribute.to_s] != a.to_s @has_changed = true @changes.push(attribute) end @attrs[attribute.to_s] = a.to_s end end end end |
Instance Method Details
#[](method) ⇒ Object
Initializes a new Base object
48 49 50 51 52 |
# File 'lib/flattr/base.rb', line 48 def [](method) self.__send__(method.to_sym) rescue NoMethodError nil end |