Sha256: 5e84027ff475b66a45d3de6f05ed3e78b73f7d0c96efed6f9aec1dcaa5417bc3

Contents?: true

Size: 478 Bytes

Versions: 12

Compression:

Stored size: 478 Bytes

Contents

# frozen_string_literal: true

module Dopstick
  module Refinements
    refine String do
      def presence
        empty? ? nil : self
      end

      def camelize
        split("-")
          .map {|word| word.split("_").map(&:capitalize).join }
          .join("::")
      end

      def underscore(separator = "/")
        split("::")
          .map {|word| word.gsub(/([A-Z]+)/m, "_\\1")[1..-1] }
          .join(separator)
          .downcase
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dopstick-0.0.12 lib/dopstick/refinements.rb
dopstick-0.0.11 lib/dopstick/refinements.rb
dopstick-0.0.10 lib/dopstick/refinements.rb
dopstick-0.0.9 lib/dopstick/refinements.rb
dopstick-0.0.8 lib/dopstick/refinements.rb
dopstick-0.0.7 lib/dopstick/refinements.rb
dopstick-0.0.6 lib/dopstick/refinements.rb
dopstick-0.0.5 lib/dopstick/refinements.rb
dopstick-0.0.4 lib/dopstick/refinements.rb
dopstick-0.0.3 lib/dopstick/refinements.rb
dopstick-0.0.2 lib/dopstick/refinements.rb
dopstick-0.0.1 lib/dopstick/refinements.rb