Class: MemDB::Idx::Chars::ReversedChars

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/mem_db/idx/chars.rb

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ ReversedChars

Returns a new instance of ReversedChars.



44
45
46
47
# File 'lib/mem_db/idx/chars.rb', line 44

def initialize(str)
  @str = str
  @length = str.length
end

Instance Method Details

#[](pos) ⇒ Object



49
50
51
# File 'lib/mem_db/idx/chars.rb', line 49

def [](pos)
  @str[@str.length - pos - 1]
end

#eachObject



61
62
63
64
65
66
67
68
69
# File 'lib/mem_db/idx/chars.rb', line 61

def each
  return to_enum unless block_given?

  i = @length - 1
  while i >= 0
    yield @str[i]
    i -= 1
  end
end

#lengthObject



53
54
55
# File 'lib/mem_db/idx/chars.rb', line 53

def length
  @str.length
end

#reverseObject



57
58
59
# File 'lib/mem_db/idx/chars.rb', line 57

def reverse
  Chars.new(@str)
end