Sha256: 2463896791fd3416f7d7b498fb1dfe6b9588f05370a447f4fe78fa0429271ba0

Contents?: true

Size: 733 Bytes

Versions: 4

Compression:

Stored size: 733 Bytes

Contents

#--
# Author::    Tyler Rick
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
# License::   Ruby License
# Submit to Facets?:: Yes! A great compliment to each_char!
# Developer notes::
#++

$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
require 'rubygems'

class String
  def each_char_with_index
    i = 0
    split(//).each do |c|
      yield i, c
      i += 1
    end
  end
end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test
require 'test/unit'

class TheTest < Test::Unit::TestCase
  def test_1
    assert_equal [[0, "a"], [1, "b"], [2, "c"]],
                 'abc'.to_enum(:each_char_with_index).to_a
  end
end
=end


Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
quality_extensions-1.3.2 lib/quality_extensions/string/each_char_with_index.rb
quality_extensions-1.3.1 lib/quality_extensions/string/each_char_with_index.rb
quality_extensions-1.3.0 lib/quality_extensions/string/each_char_with_index.rb
quality_extensions-1.1.6 lib/quality_extensions/string/each_char_with_index.rb