Sha256: 1b30fa701678af072981e460e5badfc76b87c0baf040d3e201aa488cd733a965

Contents?: true

Size: 673 Bytes

Versions: 6

Compression:

Stored size: 673 Bytes

Contents

require 'parameters/types/type'

module Parameters
  module Types
    class Proc < Type

      # The callback that will coerce values
      attr_reader :callback

      #
      # Creates a new Proc type.
      #
      # @param [#call] callback
      #   The callback that will handle the actual coercion.
      #
      def initialize(callback)
        @callback = callback
      end

      #
      # Coerces the value using the callback.
      #
      # @param [::Object] value
      #   The value to coerce.
      #
      # @return [::Object]
      #   The result of the callback.
      #
      def coerce(value)
        @callback.call(value)
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
parameters-0.4.4 lib/parameters/types/proc.rb
parameters-0.4.3 lib/parameters/types/proc.rb
parameters-0.4.2 lib/parameters/types/proc.rb
parameters-0.4.0 lib/parameters/types/proc.rb
parameters-0.3.1 lib/parameters/types/proc.rb
parameters-0.3.0 lib/parameters/types/proc.rb