Class: String
- Defined in:
- lib/contrast.rb,
lib/contrast/agent/assess/policy/propagator/split.rb
Overview
Special class to handle String#split in which, when given a block, propagates each split piece directly.
Constant Summary collapse
- CS__BLANK_RE =
/\A[[:space:]]*\z/.cs__freeze
Instance Method Summary collapse
-
#blank? ⇒ true, false
A string is blank if it’s empty or contains whitespaces only:.
- #cs__patched_string_split_special ⇒ Object
-
#split(*args, &block) ⇒ Object
Override of the the standard split method to handle the direct yield case.
Instance Method Details
#blank? ⇒ true, false
A string is blank if it’s empty or contains whitespaces only:
''.blank? # => true
' '.blank? # => true
"\t\n\r".blank? # => true
' blah '.blank? # => false
Unicode whitespace is supported:
"\u00a0".blank? # => true
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/contrast.rb', line 28 def blank? # The regexp that matches blank strings is expensive. For the case of empty # strings we can speed up this method (~3.5x) with an empty? call. The # penalty for the rest of strings is marginal. empty? || begin CS__BLANK_RE.match?(self) rescue Encoding::CompatibilityError false end end |
#cs__patched_string_split_special ⇒ Object
183 |
# File 'lib/contrast/agent/assess/policy/propagator/split.rb', line 183 alias_method :cs__patched_string_split_special, :split |
#split(*args, &block) ⇒ Object
Override of the the standard split method to handle the direct yield case.
Note: because this patch is applied before our standard propagation, this call is wrapped in it. As such, any call here happens in scope, so there is no need to manage it on our own.
189 190 191 192 193 194 195 196 197 |
# File 'lib/contrast/agent/assess/policy/propagator/split.rb', line 189 def split *args, &block if block Contrast::Agent::Assess::Policy::Propagator::Split.wrap_split(self, args) do cs__patched_string_split_special(*args, &block) end else cs__patched_string_split_special(*args, &block) end end |