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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Chars

Returns a new instance of Chars.



15
16
17
18
# File 'lib/mem_db/idx/chars.rb', line 15

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

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



24
25
26
# File 'lib/mem_db/idx/chars.rb', line 24

def length
  @length
end

Instance Method Details

#[](pos) ⇒ Object



20
21
22
# File 'lib/mem_db/idx/chars.rb', line 20

def [](pos)
  @str[pos]
end

#eachObject



30
31
32
33
34
35
36
37
38
# File 'lib/mem_db/idx/chars.rb', line 30

def each
  return to_enum unless block_given?

  i = 0
  while i < @length
    yield @str[i]
    i += 1
  end
end

#reverseObject



26
27
28
# File 'lib/mem_db/idx/chars.rb', line 26

def reverse
  ReversedChars.new(@str)
end