Class: String

Inherits:
Object show all
Defined in:
lib/nyara/patches/string.rb,
lib/nyara/patches/blank.rb,
lib/nyara/patches/to_query.rb

Overview

patch with 2.1 methods if not defined

Instance Method Summary collapse

Instance Method Details

#bObject


4
5
6
# File 'lib/nyara/patches/string.rb', line 4

def b
  dup.force_encoding 'binary'
end

#blank?Boolean

A string is blank if it's empty or contains whitespaces only:

''.blank? # => true ' '.blank? # => true ' '.blank? # => true ' something here '.blank? # => false

Returns:

  • (Boolean)

115
116
117
# File 'lib/nyara/patches/blank.rb', line 115

def blank?
  self !~ /[^[:space:]]/
end

#scrub(replacement = nil) ⇒ Object

NOTE: block unsupported


11
12
13
14
15
16
17
18
19
# File 'lib/nyara/patches/string.rb', line 11

def scrub replacement=nil
  if replacement
    replacement = replacement.encode 'UTF-16BE'
  else
    replacement = "\xFF\xFD".force_encoding 'UTF-16BE'
  end
  r = encode("UTF-16BE", undef: :replace, invalid: :replace, replace: replacement)
  r.encode("UTF-8").gsub("\0".encode("UTF-8"), '')
end