Class: Pol
- Inherits:
-
Object
- Object
- Pol
- Defined in:
- lib/pol.rb,
lib/pol/version.rb
Overview
can be lazy initalization or not
Defined Under Namespace
Classes: CreateBlockNotSupplayed, Error
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#clear_block ⇒ Object
Returns the value of attribute clear_block.
-
#create_block ⇒ Object
Returns the value of attribute create_block.
-
#queue ⇒ Object
writeonly
Sets the attribute queue.
Instance Method Summary collapse
- #clear_pool ⇒ Object
-
#initialize(&block) ⇒ Pol
constructor
A new instance of Pol.
- #set_clear_block(&block) ⇒ Object
- #with_pool ⇒ Object
Constructor Details
#initialize(&block) ⇒ Pol
Returns a new instance of Pol.
19 20 21 22 23 |
# File 'lib/pol.rb', line 19 def initialize(&block) raise CreateBlockNotSupplayed unless block self.queue = create_queue self.create_block = block end |
Instance Attribute Details
#clear_block ⇒ Object
Returns the value of attribute clear_block.
8 9 10 |
# File 'lib/pol.rb', line 8 def clear_block @clear_block end |
#create_block ⇒ Object
Returns the value of attribute create_block.
9 10 11 |
# File 'lib/pol.rb', line 9 def create_block @create_block end |
#queue=(value) ⇒ Object
Sets the attribute queue
7 8 9 |
# File 'lib/pol.rb', line 7 def queue=(value) @queue = value end |
Instance Method Details
#clear_pool ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pol.rb', line 38 def clear_pool if self.clear_block.nil? self.queue.clear true else cleared_queue = self.queue self.queue = create_queue while !cleared_queue.empty? cleared_obj = cleared_queue.pop(true) self.clear_block.call(cleared_obj) end true end end |
#set_clear_block(&block) ⇒ Object
34 35 36 |
# File 'lib/pol.rb', line 34 def set_clear_block(&block) self.clear_block = block end |
#with_pool ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/pol.rb', line 25 def with_pool begin pooled_obj = pick_from_pool yield(pooled_obj) if block_given? ensure put_to_pool(pooled_obj) end end |