Class: Rouge::Seq::Lazy

Inherits:
Object
  • Object
show all
Includes:
ISeq
Defined in:
lib/rouge/seq.rb

Overview

A lazy seq; contains the body (thunk) which is a lambda to get the “real” seq. Once evaluated (realised), the result is cached.

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Lazy

Returns a new instance of Lazy.



239
240
241
242
# File 'lib/rouge/seq.rb', line 239

def initialize(body)
  @body = body
  @realized = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



259
260
261
# File 'lib/rouge/seq.rb', line 259

def method_missing(sym, *args, &block)
  seq.send(sym, *args, &block)
end

Instance Method Details

#inspectObject



263
264
265
# File 'lib/rouge/seq.rb', line 263

def inspect
  seq.inspect
end

#seqObject



244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/rouge/seq.rb', line 244

def seq
  if @realized
    @result
  else
    @result = Rouge::Seq.seq(@body.call) || Empty
    @body = nil
    @realized = true
    @result
  end
rescue UnknownSeqError
  @realized = true
  @result = Empty
  raise
end

#to_sObject



267
268
269
# File 'lib/rouge/seq.rb', line 267

def to_s
  seq.to_s
end