Class: String

Inherits:
Object show all
Defined in:
lib/cucumber/core_ext/string.rb,
lib/cucumber/py_support/py_language.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#end_with?(str) ⇒ Boolean

1.9

Returns:

  • (Boolean)


62
63
64
65
66
# File 'lib/cucumber/py_support/py_language.rb', line 62

def end_with?(str) #:nodoc:
  str = str.to_str
  tail = self[-str.length, str.length]
  tail == str      
end

#gzub(regexp, format = nil, &proc) ⇒ Object

TODO: Use subs instead…



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cucumber/core_ext/string.rb', line 19

def gzub(regexp, format=nil, &proc)
  md = match(regexp)
  raise "#{self.inspect} doesn't match #{regexp.inspect}" if md.nil?
  
  s = dup
  pos = 0
  md.captures.each_with_index do |m, n|
    replacement = if block_given?
      proc.call(m)
    elsif Proc === format
      format.call(m)
    else
      format % m
    end
    
    if md.offset(n+1)[0]
      s[md.offset(n+1)[0] + pos, m.length] = replacement
      pos += replacement.length - m.length
    end
  end
  s
end

#indent(n) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/cucumber/core_ext/string.rb', line 2

def indent(n)
  if n >= 0
    gsub(/^/, ' ' * n)
  else
    gsub(/^ {0,#{-n}}/, "")
  end
end

#subs(re, *args) ⇒ Object

re.source.gsub(/(*)/, ‘$var’) Cumulative #sub



12
13
14
15
16
# File 'lib/cucumber/core_ext/string.rb', line 12

def subs(re, *args)
  args.inject(self) do |s,arg|
    s.sub(re, arg)
  end
end