Class: Rouge::Seq::Array

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

Overview

A seq over a Ruby Array.

Instance Method Summary collapse

Methods included from ASeq

#==, #cons, #count, #inspect, #more, #seq, #to_s

Constructor Details

#initialize(array, idx) ⇒ Array

Returns a new instance of Array.



199
200
201
# File 'lib/rouge/seq.rb', line 199

def initialize(array, idx)
  @array, @idx = array, idx
end

Instance Method Details

#[](idx) ⇒ Object



217
218
219
# File 'lib/rouge/seq.rb', line 217

def [](idx)
  @array[@idx + idx]
end

#each(&block) ⇒ Object



225
226
227
# File 'lib/rouge/seq.rb', line 225

def each(&block)
  to_a.each(&block)
end

#firstObject



203
204
205
# File 'lib/rouge/seq.rb', line 203

def first
  @array[@idx]
end

#lengthObject



213
214
215
# File 'lib/rouge/seq.rb', line 213

def length
  @array.length - @idx
end

#map(&block) ⇒ Object



229
230
231
# File 'lib/rouge/seq.rb', line 229

def map(&block)
  to_a.map(&block)
end

#nextObject



207
208
209
210
211
# File 'lib/rouge/seq.rb', line 207

def next
  if @idx + 1 < @array.length
    Array.new(@array, @idx + 1)
  end
end

#to_aObject



221
222
223
# File 'lib/rouge/seq.rb', line 221

def to_a
  @array[@idx..-1]
end