Class: Capgun::Base
- Inherits:
-
Object
- Object
- Capgun::Base
- Defined in:
- lib/capgun/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.
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#[](method) ⇒ Object
Initializes a new Base object.
-
#initialize(attrs = {}) ⇒ Capgun::Base
constructor
Initializes a new Base object.
Constructor Details
#initialize(attrs = {}) ⇒ Capgun::Base
Initializes a new Base object
28 29 30 |
# File 'lib/capgun/base.rb', line 28 def initialize(attrs={}) @attrs = attrs.dup end |
Instance Attribute Details
#attrs ⇒ Object Also known as: to_hash
Returns the value of attribute attrs.
5 6 7 |
# File 'lib/capgun/base.rb', line 5 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
14 15 16 17 18 19 20 21 22 |
# File 'lib/capgun/base.rb', line 14 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 |
Instance Method Details
#==(other) ⇒ Boolean
43 44 45 |
# File 'lib/capgun/base.rb', line 43 def ==(other) super || (other.class == self.class && other.id == self.id) end |
#[](method) ⇒ Object
Initializes a new Base object
35 36 37 38 39 |
# File 'lib/capgun/base.rb', line 35 def [](method) self.__send__(method.to_sym) rescue NoMethodError nil end |