Class: MemDB::Idx::Chars::Chars
- Inherits:
-
Object
- Object
- MemDB::Idx::Chars::Chars
- Includes:
- Enumerable
- Defined in:
- lib/mem_db/idx/chars.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Instance Method Summary collapse
- #[](pos) ⇒ Object
- #each ⇒ Object
-
#initialize(str) ⇒ Chars
constructor
A new instance of Chars.
- #reverse ⇒ Object
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
#length ⇒ Object (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 |
#each ⇒ Object
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 |
#reverse ⇒ Object
26 27 28 |
# File 'lib/mem_db/idx/chars.rb', line 26 def reverse ReversedChars.new(@str) end |