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

#contain?(value) ⇒ Boolean Also known as: contains?

Returns:

  • (Boolean)


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

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

#match?(regex) ⇒ Boolean Also known as: matches?

Returns:

  • (Boolean)


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

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

#truncate(length = 30, truncate_string = "...") ⇒ Object

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