lib/rouge/seq.rb in rouge-lang-0.0.5 vs lib/rouge/seq.rb in rouge-lang-0.0.6

- old
+ new

@@ -62,11 +62,13 @@ end len end - alias count length + def count + length + end def [](idx) return to_a[idx] if idx.is_a? Range cursor = self @@ -184,9 +186,29 @@ def next if @idx + 1 < @array.length Array.new(@array, @idx + 1) end + end + + def length + @array.length - @idx + end + + def [](idx) + @array[@idx + idx] + end + + def to_a + @array[@idx..-1] + end + + def each(&block) + to_a.each(&block) + end + + def map(&block) + to_a.map(&block) end end # A lazy seq; contains the body (thunk) which is a lambda to get the "real" # seq. Once evaluated (realised), the result is cached.