Sha256: 04b68c7f108c09fde51b126f2ba5ad933858d80f5df4f18c61f10fdc49a8965f
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 KB
Contents
# frozen_string_literal: true module Kind module KIND extend self def null?(value) # :nodoc: value.nil? || Undefined == value end def of?(kind, values) # :nodoc: of_kind = -> value { kind === value } values.empty? ? of_kind : values.all?(&of_kind) end def of!(kind, value, kind_name = nil) # :nodoc: return value if kind === value error!(kind_name || kind.name, value) end def error!(kind_name, value, label = nil) # :nodoc: raise Error.new(kind_name, value, label: label) end def of_class?(value) # :nodoc: value.kind_of?(::Class) end def of_module?(value) # :nodoc: ::Module == value || (value.kind_of?(::Module) && !of_class?(value)) end def of_module_or_class!(value) # :nodoc: of!(::Module, value, 'Module/Class') end def respond_to!(method_name, value) # :nodoc: return value if value.respond_to?(method_name) raise Error.new("expected #{value} to respond to :#{method_name}") end def interface?(method_names, value) # :nodoc: method_names.all? { |method_name| value.respond_to?(method_name) } end def value(kind, arg, default) # :nodoc: kind === arg ? arg : default end def is?(expected, value) # :nodoc: is(of_module_or_class!(expected), value) end private def is(expected_kind, value) # :nodoc: kind = of_module_or_class!(value) if of_class?(kind) kind <= expected_kind || expected_kind == ::Class else kind == expected_kind || kind.kind_of?(expected_kind) end end end private_constant :KIND end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
kind-5.2.0 | lib/kind/__lib__/kind.rb |