Sha256: 186b916bd5d26438c06ab2938e3706e76af6569cf70644dee429e3d566e7b097

Contents?: true

Size: 760 Bytes

Versions: 1

Compression:

Stored size: 760 Bytes

Contents

module Polyfill
  module V2_4
    module Comparable
      module Clamp
        module Method
          def clamp(min, max)
            if min > max
              raise ArgumentError, 'min argument must be smaller than max argument'
            end

            return min if min > self
            return max if max < self
            self
          end if RUBY_VERSION < '2.4.0'

          def respond_to?(method, *)
            return true if method.to_sym == :clamp

            super
          end if RUBY_VERSION < '2.4.0'
        end

        refine ::Numeric do
          include Method
        end
        refine ::String do
          include Method
        end
        refine ::Time do
          include Method
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
polyfill-0.1.0 lib/polyfill/v2_4/comparable/clamp.rb