Sha256: a194925968850c991725a8017421a049a2b209912d2cc5a5afdc3b10f146f71a

Contents?: true

Size: 897 Bytes

Versions: 2

Compression:

Stored size: 897 Bytes

Contents

class String #:nodoc:
  def indent(n)
    if n >= 0
      gsub(/^/, ' ' * n)
    else
      gsub(/^ {0,#{-n}}/, "")
    end
  end
  
  # TODO: Move to StepMatch
  # +groups+ is an array of 2-element arrays, where
  # the 1st element is the value of a regexp match group,
  # and the 2nd element is its start index.
  def gzub(groups, format=nil, &proc)
    s = dup
    offset = 0
    groups.each do |group|
      replacement = if block_given?
        proc.call(group.val)
      elsif Proc === format
        format.call(group.val)
      else
        format % group.val
      end
      
      s[group.start + offset, group.val.length] = replacement
      offset += replacement.length - group.val.length
    end
    s
  end

  if (Cucumber::JRUBY && Cucumber::RAILS) || Cucumber::RUBY_1_9
    # Workaround for http://tinyurl.com/55uu3u 
    alias jlength length
  else
    require 'jcode'
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
aslakhellesoy-cucumber-0.3.102 lib/cucumber/core_ext/string.rb
cucumber-0.3.102 lib/cucumber/core_ext/string.rb