Sha256: 5457e975ea2fc27e13c5d365fbce1e9bc54b7d7e64c6f54b5b422a7141e1c070

Contents?: true

Size: 741 Bytes

Versions: 3

Compression:

Stored size: 741 Bytes

Contents

module Polyfill
  module V2_4
    module Comparable
      module Instance
        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
          end

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

          def self.included(base)
            base.include Method
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
polyfill-0.6.0 lib/polyfill/v2_4/comparable/instance/clamp.rb
polyfill-0.5.0 lib/polyfill/v2_4/comparable/instance/clamp.rb
polyfill-0.4.0 lib/polyfill/v2_4/comparable/instance/clamp.rb