Class: Range::Seq

Inherits:
Object show all
Includes:
Apricot::Seq
Defined in:
lib/apricot/ruby_ext.rb

Instance Method Summary collapse

Methods included from Apricot::Seq

#<=>, #cons, #empty?, #hash, #last, #rest, #to_s, #to_seq

Methods included from Enumerable

#to_list

Constructor Details

#initialize(first, last, exclusive) ⇒ Seq

Returns a new instance of Seq.



193
194
195
196
197
# File 'lib/apricot/ruby_ext.rb', line 193

def initialize(first, last, exclusive)
  @first = first
  @last = last
  @exclusive = exclusive
end

Instance Method Details

#eachObject



213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/apricot/ruby_ext.rb', line 213

def each
  prev = nil
  val = @first

  until prev == @last || (val == @last && @exclusive)
    yield val
    prev = val
    val = val.succ
  end

  self
end

#firstObject



199
200
201
# File 'lib/apricot/ruby_ext.rb', line 199

def first
  @first
end

#nextObject



203
204
205
206
207
208
209
210
211
# File 'lib/apricot/ruby_ext.rb', line 203

def next
  next_val = @first.succ

  if @first == @last || (next_val == @last && @exclusive)
    nil
  else
    Seq.new(next_val, @last, @exclusive)
  end
end