Class: String

Inherits:
Object show all
Defined in:
lib/vex/boot/blank.rb,
lib/vex/boot/string.rb,
lib/vex/base/object/insp.rb

Direct Known Subclasses

Net::HTTPExt::Response

Defined Under Namespace

Modules: Etest

Constant Summary collapse

INSP_TRUNCATE_LEN =
30

Instance Method Summary collapse

Instance Method Details

#constantizeObject

Raises:

  • (ArgumentError)

14
15
16
17
18
19
20
21
22
23
# File 'lib/vex/boot/string.rb', line 14

def constantize
  names = self.split('::')
  raise ArgumentError, "Cannot be blank" if blank?
  
  names.shift if names.first.empty?

  names.inject(Object) do |constant, name|
    constant.const_get(name) || constant.const_missing(name)
  end
end

#ends_with?(other) ⇒ Boolean

Returns:

  • (Boolean)

8
9
10
11
12
# File 'lib/vex/boot/string.rb', line 8

def ends_with?(other)
  return false if other.length > length

  self[self.length-other.length..-1] == other
end

#inspObject


30
31
32
33
34
35
# File 'lib/vex/base/object/insp.rb', line 30

def insp
  return inspect unless length > INSP_TRUNCATE_LEN
  
  l = INSP_TRUNCATE_LEN - 3
  (self[0...l].to_s + "...").inspect
end

#starts_with?(other) ⇒ Boolean

Returns:

  • (Boolean)

2
3
4
5
6
# File 'lib/vex/boot/string.rb', line 2

def starts_with?(other)
  return false if other.length > length

  self[0, other.length] == other
end