module Rdoba::Mixin::ReverseString

Constants

Aliases
Fixups

Public Instance Methods

__rdoba_mixin_reverse__(step = 1) click to toggle source
# File lib/rdoba/mixin.rb, line 42
def __rdoba_mixin_reverse__ step = 1
   if ( !step.is_a?( Numeric ) || step < 0 ) && step != :byte_by_byte
      raise "Invalid step value #{step.inspect}" ; end

   if step == :byte_by_byte || step == String::ByteByByte
      arr = []
      self.each_byte do | byte |
         arr << byte.chr ; end
      arr.reverse.join.force_encoding( self.encoding )
   elsif step == 1
      __rdoba_mixin_reverse_orig__
   elsif step > 1
      res = ''
      offset = (self.size + 1) / step * step - step
      ( 0..offset ).step( step ) do | shift |
         res += self[ offset - shift..offset - shift + 1 ] ; end
      res ; end ; end