Runtime assertions for Ruby literal.fun
ruby
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move rest kwargs for fewer allocations

+17 -17
+11 -11
lib/literal/types.rb
··· 95 95 if a.length == 1 && k.length == 0 96 96 a[0] 97 97 else 98 - ConstraintType.new(*a, **k) 98 + ConstraintType.new(a, k) 99 99 end 100 100 end 101 101 ··· 234 234 end 235 235 236 236 # Matches if the value responds to all the given methods. 237 - def _Interface(...) 238 - InterfaceType.new(...) 237 + def _Interface(*methods) 238 + InterfaceType.new(methods) 239 239 end 240 240 241 241 # Nilable version of `_Interface` ··· 246 246 end 247 247 248 248 # Matches if *all* given types are matched. 249 - def _Intersection(...) 250 - IntersectionType.new(...) 249 + def _Intersection(*types) 250 + IntersectionType.new(types) 251 251 end 252 252 253 253 # Nilable version of `_Intersection` ··· 284 284 # ```ruby 285 285 # _Map(name: String, age: Integer) 286 286 # ``` 287 - def _Map(...) 288 - MapType.new(...) 287 + def _Map(**shape) 288 + MapType.new(shape) 289 289 end 290 290 291 291 # Nilable version of `_Map` ··· 415 415 # ```ruby 416 416 # _Tuple(String, Integer, Integer) 417 417 # ``` 418 - def _Tuple(...) 419 - TupleType.new(...) 418 + def _Tuple(*types) 419 + TupleType.new(types) 420 420 end 421 421 422 422 # Nilable version of `_Typle` ··· 430 430 end 431 431 432 432 # Matches if *any* given type is matched. 433 - def _Union(...) 434 - UnionType.new(...) 433 + def _Union(*types) 434 + UnionType.new(types) 435 435 end 436 436 437 437 # Nilable version of `_Union`
+1 -1
lib/literal/types/constraint_type.rb
··· 4 4 class Literal::Types::ConstraintType 5 5 include Literal::Type 6 6 7 - def initialize(*object_constraints, **property_constraints) 7 + def initialize(object_constraints, property_constraints) 8 8 @object_constraints = object_constraints 9 9 @property_constraints = property_constraints 10 10 freeze
+1 -1
lib/literal/types/interface_type.rb
··· 7 7 # List of `===` method owners where the comparison will only match for objects with the same class 8 8 OwnClassTypeMethodOwners = Set[String, Integer, Kernel, Float, NilClass, TrueClass, FalseClass].freeze 9 9 10 - def initialize(*methods) 10 + def initialize(methods) 11 11 raise Literal::ArgumentError.new("_Interface type must have at least one method.") if methods.size < 1 12 12 @methods = methods.to_set.freeze 13 13 freeze
+1 -1
lib/literal/types/intersection_type.rb
··· 4 4 class Literal::Types::IntersectionType 5 5 include Literal::Type 6 6 7 - def initialize(*types) 7 + def initialize(types) 8 8 raise Literal::ArgumentError.new("_Intersection type must have at least one type.") if types.size < 1 9 9 10 10 @types = types
+1 -1
lib/literal/types/map_type.rb
··· 4 4 class Literal::Types::MapType 5 5 include Literal::Type 6 6 7 - def initialize(**shape) 7 + def initialize(shape) 8 8 @shape = shape 9 9 freeze 10 10 end
+1 -1
lib/literal/types/tuple_type.rb
··· 4 4 class Literal::Types::TupleType 5 5 include Literal::Type 6 6 7 - def initialize(*types) 7 + def initialize(types) 8 8 raise Literal::ArgumentError.new("_Tuple type must have at least one type.") if types.size < 1 9 9 10 10 @types = types
+1 -1
lib/literal/types/union_type.rb
··· 4 4 include Enumerable 5 5 include Literal::Type 6 6 7 - def initialize(*queue) 7 + def initialize(queue) 8 8 raise Literal::ArgumentError.new("_Union type must have at least one type.") if queue.size < 1 9 9 types = [] 10 10 primitives = Set[]