Class: String

Inherits:
Object show all
Defined in:
merb-core/lib/merb-core/test/test_ext/string.rb,
merb-helpers/lib/merb-helpers/core_ext.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) contain?(value) Also known as: contains?



2
3
4
# File 'merb-core/lib/merb-core/test/test_ext/string.rb', line 2

def contain?(value)
  self.include?(value)
end

- (Boolean) match?(regex) Also known as: matches?



8
9
10
# File 'merb-core/lib/merb-core/test/test_ext/string.rb', line 8

def match?(regex)
  self.match(regex)
end

- (Object) truncate(length = 30, truncate_string = "...")

Truncates a string to the given length and appends the given suffix if the string is, in fact, truncated.

Examples:

"This is a long string right here".truncate(10, "...")
#=> "This is..."


54
55
56
57
58
# File 'merb-helpers/lib/merb-helpers/core_ext.rb', line 54

def truncate(length = 30, truncate_string = "...")
  return self unless self.length > length
  length = length - truncate_string.split(//).length
  self[0...length] + truncate_string
end