lib/kind.rb in kind-2.1.0 vs lib/kind.rb in kind-2.2.0

- old
+ new

@@ -16,13 +16,13 @@ WRONG_NUMBER_OF_ARGUMENTS = 'wrong number of arguments (given 1, expected 2)'.freeze private_constant :WRONG_NUMBER_OF_ARGUMENTS def self.is(expected = Undefined, object = Undefined) - return Is if expected == Undefined && object == Undefined + return Is if Undefined == expected && Undefined == object - return Kind::Is.(expected, object) if object != Undefined + return Kind::Is.(expected, object) if Undefined != object raise ArgumentError, WRONG_NUMBER_OF_ARGUMENTS end MODULE_OR_CLASS = 'Module/Class'.freeze @@ -34,13 +34,13 @@ end __checkers__ def self.of(kind = Undefined, object = Undefined) - return Of if kind == Undefined && object == Undefined + return Of if Undefined == kind && Undefined == object - return Kind::Of.(kind, object) if object != Undefined + return Kind::Of.(kind, object) if Undefined != object __checkers__[kind] ||= begin kind_name = kind.name if Kind::Of.const_defined?(kind_name, false) @@ -63,11 +63,11 @@ def self.Class(value) value.kind_of?(::Class) end def self.Module(value) - value == ::Module || (value.is_a?(::Module) && !self.Class(value)) + ::Module == value || (value.is_a?(::Module) && !self.Class(value)) end def self.Boolean(value) Kind.of.Class(value) <= TrueClass || value <= FalseClass end @@ -79,11 +79,11 @@ module Of # -- Class def self.Class(object = Undefined) - return Class if object == Undefined + return Class if Undefined == object self.call(::Class, object) end const_set(:Class, ::Module.new do @@ -101,20 +101,20 @@ end # -- Module def self.Module(object = Undefined) - return Module if object == Undefined + return Module if Undefined == object self.call(::Module, object) end const_set(:Module, ::Module.new do extend Checkable def self.__kind_undefined(value) - __kind_error(Kind::Undefined) if value == Kind::Undefined + __kind_error(Kind::Undefined) if Kind::Undefined == value yield end def self.__kind_error(value) @@ -135,11 +135,11 @@ default = options[:or] if ::Kind::Maybe::Value.none?(default) __kind_undefined(value) { __kind_of(value) } else - return value if value != Kind::Undefined && instance?(value) + return value if Kind::Undefined != value && instance?(value) __kind_undefined(default) { __kind_of(default) } end end @@ -153,11 +153,11 @@ # -- Boolean def self.Boolean(object = Undefined, options = Empty::HASH) default = options[:or] - return Kind::Of::Boolean if object == Undefined && default.nil? + return Kind::Of::Boolean if Undefined == object && default.nil? bool = object.nil? ? default : object return bool if bool.is_a?(::TrueClass) || bool.is_a?(::FalseClass) @@ -175,18 +175,18 @@ default = options[:or] if ::Kind::Maybe::Value.none?(default) __kind_undefined(value) { Kind::Of::Boolean(value) } else - return value if value != Kind::Undefined && instance?(value) + return value if Kind::Undefined != value && instance?(value) __kind_undefined(default) { Kind::Of::Boolean(default) } end end def self.__kind_undefined(value) - if value == Kind::Undefined + if Kind::Undefined == value raise Kind::Error.new('Boolean'.freeze, Kind::Undefined) else yield end end @@ -208,11 +208,11 @@ # -- Lambda def self.Lambda(object = Undefined, options = Empty::HASH) default = options[:or] - return Kind::Of::Lambda if object == Undefined && default.nil? + return Kind::Of::Lambda if Undefined == object && default.nil? func = object || default return func if func.is_a?(::Proc) && func.lambda? @@ -228,18 +228,18 @@ default = options[:or] if ::Kind::Maybe::Value.none?(default) __kind_undefined(value) { Kind::Of::Lambda(value) } else - return value if value != Kind::Undefined && instance?(value) + return value if Kind::Undefined != value && instance?(value) __kind_undefined(default) { Kind::Of::Lambda(default) } end end def self.__kind_undefined(value) - if value == Kind::Undefined + if Kind::Undefined == value raise Kind::Error.new('Lambda'.freeze, Kind::Undefined) else yield end end @@ -256,11 +256,11 @@ # -- Callable def self.Callable(object = Undefined, options = Empty::HASH) default = options[:or] - return Kind::Of::Callable if object == Undefined && default.nil? + return Kind::Of::Callable if Undefined == object && default.nil? callable = object || default return callable if callable.respond_to?(:call) @@ -280,17 +280,17 @@ default = options[:or] if ::Kind::Maybe::Value.none?(default) __kind_undefined(value) { Kind::Of::Callable(value) } else - return value if value != Kind::Undefined && instance?(value) + return value if Kind::Undefined != value && instance?(value) __kind_undefined(default) { Kind::Of::Callable(default) } end end def self.__kind_undefined(value) - if value == Kind::Undefined + if Kind::Undefined == value raise Kind::Error.new('Callable'.freeze, Kind::Undefined) else yield end end