Sha256: 38902eaf9a2f40a431eca23bd6e73732cec41ca8b0b6a50778d36769d888668e

Contents?: true

Size: 995 Bytes

Versions: 50

Compression:

Stored size: 995 Bytes

Contents

module Hirb
  # Provides string helpers to deal with UTF-8 and ruby 1.8.x
  module String
    extend self
    # :stopdoc:
    if RUBY_VERSION < '1.9'
      def size(string)
        string.scan(/./).length
      end

      def ljust(string, desired_length)
        leftover = desired_length - size(string)
        leftover > 0 ? string + " " * leftover : string
      end

      def rjust(string, desired_length)
        leftover = desired_length - size(string)
        leftover > 0 ? " " * leftover + string : string
      end

      def slice(string, start, finish)
        string.scan(/./).slice(start, finish).join('')
      end
    else
      def size(string)
        string.length
      end

      def ljust(string, desired_length)
        string.ljust(desired_length)
      end

      def rjust(string, desired_length)
        string.rjust(desired_length)
      end

      def slice(*args)
        string = args.shift
        string.slice(*args)
      end
    end
    #:startdoc:
  end
end

Version data entries

50 entries across 49 versions & 6 rubygems

Version Path
hirber-0.8.5 lib/hirb/string.rb
hirber-0.8.4 lib/hirb/string.rb
hirber-0.8.2 lib/hirb/string.rb
hirber-0.8.1 lib/hirb/string.rb
hirber-0.8.0 lib/hirb/string.rb
hirb-0.7.3 lib/hirb/string.rb
cldwalker-hirb-0.2.4 lib/hirb/string.rb
cldwalker-hirb-0.2.5 lib/hirb/string.rb
cldwalker-hirb-0.2.6 lib/hirb/string.rb
climine-0.0.7 vendor/bundle/ruby/2.1.0/gems/hirb-0.7.1/lib/hirb/string.rb
climine-0.0.7 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/lib/hirb/string.rb
hirb-0.7.2 lib/hirb/string.rb
climine-0.0.6 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/lib/hirb/string.rb
climine-0.0.5 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/lib/hirb/string.rb
climine-0.0.4 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/lib/hirb/string.rb
climine-0.0.3 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/lib/hirb/string.rb
climine-0.0.2 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/lib/hirb/string.rb
climine-0.0.1 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/lib/hirb/string.rb
hirb-0.7.1 lib/hirb/string.rb
hirb-0.7.0 lib/hirb/string.rb