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