Sha256: 5dd10c2ee863ee454d45a85f57c945da10d8d499836929aae73a24f8c13b35b7

Contents?: true

Size: 633 Bytes

Versions: 2

Compression:

Stored size: 633 Bytes

Contents

module DuckPuncher
  module Ducks
    module String
      def pluralize(count)
        "#{self}#{'s' if count != 1}"
      end unless method_defined?(:pluralize)

      def underscore
        gsub(/\B([A-Z])([a-z_0-9])/, '_\1\2').gsub('::', '/').downcase
      end unless method_defined?(:underscore)

      def to_boolean(strict = false)
        @boolean_map ||= begin
          truths, falsities = %w(true 1 yes y on), ['false', '0', 'no', 'n', 'off', '']
          Hash[truths.product([true]) + falsities.product([false])]
        end
        strict ? !downcase.in?(falsities) : @boolean_map[downcase]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
duck_puncher-2.6.0 lib/duck_puncher/ducks/string.rb
duck_puncher-2.5.1 lib/duck_puncher/ducks/string.rb