Class: Gumdrop::ContextPool
- Inherits:
-
Object
- Object
- Gumdrop::ContextPool
- Defined in:
- lib/gumdrop/renderer.rb
Instance Method Summary collapse
- #current ⇒ Object
-
#initialize(renderer, size = 3) ⇒ ContextPool
constructor
A new instance of ContextPool.
- #next ⇒ Object
- #pop ⇒ Object
- #prev ⇒ Object
- #root ⇒ Object
- #size ⇒ Object
- #sub_context ⇒ Object
Constructor Details
#initialize(renderer, size = 3) ⇒ ContextPool
Returns a new instance of ContextPool.
210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/gumdrop/renderer.rb', line 210 def initialize(renderer, size=3) @_current= -1 @renderer= renderer @pool=[] prev= nil size.times do |i| ctx= RenderContext.new nil, nil, renderer, prev @pool << ctx prev= ctx end end |
Instance Method Details
#current ⇒ Object
234 235 236 |
# File 'lib/gumdrop/renderer.rb', line 234 def current @pool[@_current] end |
#next ⇒ Object
228 229 230 231 232 |
# File 'lib/gumdrop/renderer.rb', line 228 def next @_current += 1 @pool << RenderContext.new( nil, nil, @renderer, prev ) if @_current == @pool.size @pool[@_current] end |
#pop ⇒ Object
242 243 244 245 |
# File 'lib/gumdrop/renderer.rb', line 242 def pop @_current -= 1 @pool[@_current] end |
#prev ⇒ Object
238 239 240 |
# File 'lib/gumdrop/renderer.rb', line 238 def prev @pool[@_current - 1] rescue nil end |
#root ⇒ Object
247 248 249 |
# File 'lib/gumdrop/renderer.rb', line 247 def root @pool[0] end |
#size ⇒ Object
251 252 253 |
# File 'lib/gumdrop/renderer.rb', line 251 def size @_current + 1 end |
#sub_context ⇒ Object
222 223 224 225 226 |
# File 'lib/gumdrop/renderer.rb', line 222 def sub_context result= yield self.next, self.prev self.pop result end |