Class: ActiveSP::Associations::AssociationProxy
- Inherits:
-
Object
- Object
- ActiveSP::Associations::AssociationProxy
- Includes:
- Enumerable
- Defined in:
- lib/activesp/associations.rb
Instance Method Summary collapse
- #count ⇒ Object
- #each(&blk) ⇒ Object
- #first ⇒ Object
-
#initialize(object, &element_getter) ⇒ AssociationProxy
constructor
A new instance of AssociationProxy.
- #last ⇒ Object
Constructor Details
#initialize(object, &element_getter) ⇒ AssociationProxy
Returns a new instance of AssociationProxy.
35 36 37 38 |
# File 'lib/activesp/associations.rb', line 35 def initialize(object, &element_getter) @object = object @element_getter = element_getter end |
Instance Method Details
#count ⇒ Object
53 54 55 |
# File 'lib/activesp/associations.rb', line 53 def count inject(0) { |cnt, _| cnt + 1 } end |
#each(&blk) ⇒ Object
40 41 42 |
# File 'lib/activesp/associations.rb', line 40 def each(&blk) @element_getter.call(blk) end |
#first ⇒ Object
44 45 46 47 |
# File 'lib/activesp/associations.rb', line 44 def first each { |element| return element } nil end |
#last ⇒ Object
49 50 51 |
# File 'lib/activesp/associations.rb', line 49 def last inject { |_, element| element } end |