Class: String
- Defined in:
- lib/core_ext/blank.rb,
lib/core_ext/snake_case.rb more...
Constant Summary collapse
- NON_WHITESPACE_REGEXP =
0x3000: fullwidth whitespace
%r![^\s#{[0x3000].pack("U")}]!
Instance Method Summary collapse
-
#blank? ⇒ Boolean
A string is blank if it’s empty or contains whitespaces only:.
- #to_snake_case ⇒ Object
-
#to_snake_case! ⇒ Object
ruby mutation methods have the expectation to return self if a mutation occurred, nil otherwise.
Instance Method Details
permalink #blank? ⇒ Boolean
A string is blank if it’s empty or contains whitespaces only:
"".blank? # => true
" ".blank? # => true
" ".blank? # => true
" something here ".blank? # => false
103 104 105 |
# File 'lib/core_ext/blank.rb', line 103 def blank? self !~ NON_WHITESPACE_REGEXP end |
permalink #to_snake_case ⇒ Object
[View source]
10 11 12 |
# File 'lib/core_ext/snake_case.rb', line 10 def to_snake_case dup.tap { |s| s.to_snake_case! } end |
permalink #to_snake_case! ⇒ Object
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)
5 6 7 8 |
# File 'lib/core_ext/snake_case.rb', line 5 def to_snake_case! gsub!(/(.)([A-Z])/,'\1_\2') downcase! end |