Sha256: 30cde01ba5153b932f6da7aaf3ecc241378ed3e57fe56463fc90f16e23c73314
Contents?: true
Size: 830 Bytes
Versions: 24
Compression:
Stored size: 830 Bytes
Contents
# frozen_string_literal: true module ActiveModel module Type class Registry # :nodoc: def initialize @registrations = {} end def initialize_copy(other) @registrations = @registrations.dup super end def register(type_name, klass = nil, &block) unless block_given? block = proc { |_, *args| klass.new(*args) } block.ruby2_keywords if block.respond_to?(:ruby2_keywords) end registrations[type_name] = block end def lookup(symbol, ...) registration = registrations[symbol] if registration registration.call(symbol, ...) else raise ArgumentError, "Unknown type #{symbol.inspect}" end end private attr_reader :registrations end end end
Version data entries
24 entries across 24 versions & 2 rubygems