module Sanity::Refinements::Strings

String refinements based on ActiveSupport methods.

Using refinements as to:

1) not pollute the global namespace
2) not conflict with ActiveSupport in a Rails based project

These methods are defined in the way as needed in this gem. They are not meant to replace the more robust ActiveSupport methods.

Defining these here, removes the need for adding ActiveSupport as a dependency

Public Instance Methods

camelize_lower() click to toggle source
# File lib/sanity/refinements/strings.rb, line 18
def camelize_lower
  split("_")[0..].each_with_index.map do |val, idx|
    idx != 0 ? val.capitalize : val
  end.join
end
classify() click to toggle source
# File lib/sanity/refinements/strings.rb, line 24
def classify
  split("_").map(&:capitalize).join
end
demodulize() click to toggle source
# File lib/sanity/refinements/strings.rb, line 28
def demodulize
  split("::")[-1]
end
underscore() click to toggle source
# File lib/sanity/refinements/strings.rb, line 32
def underscore
  split(/(?=[A-Z])/).map(&:downcase).join("_")
end