Class: String

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

Direct Known Subclasses

Net::HTTPExt::Response

Defined Under Namespace

Modules: Etest, Iconvert

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

#iconv(encoding) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/vex/base/string/iconvert.rb', line 64

def iconv(encoding)
  if encoding.is_a?(Hash)
    invalid_argument! encoding unless encoding.length == 1
    ie, oe = *encoding.first
  else
    ie, oe = nil, encoding
  end

  Iconvert.convert self, ie, oe
rescue Iconv::InvalidEncoding
  Iconvert.invalid_encoding ie, oe
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