class String

Constants

NON_WHITESPACE_REGEXP

0x3000: fullwidth whitespace

Public Instance Methods

blank?() click to toggle source

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

"".blank?                 # => true
"   ".blank?              # => true
" ".blank?               # => true
" something here ".blank? # => false
# File lib/core_ext/blank.rb, line 103
def blank?
  self !~ NON_WHITESPACE_REGEXP
end
to_snake_case() click to toggle source
# File lib/core_ext/snake_case.rb, line 10
def to_snake_case
  dup.tap { |s| s.to_snake_case! }
end
to_snake_case!() click to toggle source

ruby mutation methods have the expectation to return self if a mutation occurred, nil otherwise. (see www.ruby-doc.org/core-1.9.3/String.html#method-i-gsub-21)

# File lib/core_ext/snake_case.rb, line 5
def to_snake_case!
  gsub!(/(.)([A-Z])/,'\1_\2')
  downcase!
end