class String
Public Instance Methods
blank?()
click to toggle source
# File lib/core_ext/string.rb, line 4 def blank? empty? || /\A[[:space:]]*\z/.match?(self) end
present?()
click to toggle source
# File lib/core_ext/string.rb, line 8 def present? !blank? end
to_camel_case(uppercase_first_letter = false)
click to toggle source
Convert string to CamelCase
# File lib/core_ext/string.rb, line 13 def to_camel_case(uppercase_first_letter = false) string = self string = if uppercase_first_letter string.sub(/^[a-z\d]*/, &:capitalize) else string.sub(/^(?:(?=\b|[A-Z_])|\w)/, &:downcase) end string.gsub(%r{(?:_|(/))([a-z\d]*)}) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }.gsub('/', '::') end
to_snake_case()
click to toggle source
Convert string to snake_case
# File lib/core_ext/string.rb, line 24 def to_snake_case gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end