class Rb::RubyIterator

Attributes

at[RW]
len[RW]
ref[RW]

Public Class Methods

new(x) click to toggle source
# File lib/lib/rb/ruby_iterator.rb, line 7
def initialize(x)
  if x.is_a?(Hash) 
    @ref = x.values.each
    @at = 0
    @len = x.size
  elsif x.respond_to?("each") 
    @ref = x.each
    @at = 0
    @len = x.size
  elsif x.respond_to?("iterator") 
    @ref = x.iterator
    @at = -1
    @at = -2 if !@ref.respond_to?("has_next")
  else 
    @ref = x
    @at = -2
  end
end

Public Instance Methods

_next() click to toggle source
# File lib/lib/rb/ruby_iterator.rb, line 40
def _next 
  return @ref[:_next].call if @at == -1
  return @ref[:_next][:call].call if @at == -2
  @at+=1
  @ref.next
end
has_next() click to toggle source
# File lib/lib/rb/ruby_iterator.rb, line 34
def has_next 
  return @ref[:has_next].call if @at == -1
  return @ref[:has_next][:call].call if @at == -2
  @at < @len
end