Runtime assertions for Ruby literal.fun
ruby
5
fork

Configure Feed

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

Rename `_Unit` to `_SameObject`

+25 -25
+6 -6
lib/literal/types.rb
··· 467 467 ) 468 468 end 469 469 470 - # The unit type is a type that matches only the same object 471 - def _Unit(object) 472 - UnitType.new(object) 470 + # Matches only the same object identity. 471 + def _SameObject(object) 472 + SameObjectType.new(object) 473 473 end 474 474 475 - # Nilable version of `_Unit` 476 - def _Unit?(...) 475 + # Nilable version of `_SameObject` 476 + def _SameObject?(...) 477 477 _Nilable( 478 - _Unit(...) 478 + _SameObject(...) 479 479 ) 480 480 end 481 481
+2 -2
lib/literal/types/unit_type.rb lib/literal/types/same_object_type.rb
··· 1 1 # frozen_string_literal: true 2 2 3 3 # @api private 4 - class Literal::Types::UnitType 4 + class Literal::Types::SameObjectType 5 5 include Literal::Type 6 6 7 7 EQUAL_METHOD = BasicObject.instance_method(:equal?) ··· 19 19 20 20 def >=(other, context: nil) 21 21 case other 22 - when Literal::Types::UnitType 22 + when Literal::Types::SameObjectType 23 23 EQUAL_METHOD.bind_call(@object, other.object) 24 24 else 25 25 false
+17
test/types/_same_object.test.rb
··· 1 + # frozen_string_literal: true 2 + 3 + include Literal::Types 4 + 5 + test "===" do 6 + object = -> { "hello" } 7 + 8 + assert _SameObject(object) === object 9 + refute _SameObject(object) === -> { "hello" } 10 + end 11 + 12 + test "hierarchy" do 13 + object = "a" 14 + 15 + assert_subtype _SameObject(object), _SameObject(object) 16 + refute_subtype _SameObject(object), _SameObject(+"a") 17 + end
-17
test/types/_unit.test.rb
··· 1 - # frozen_string_literal: true 2 - 3 - include Literal::Types 4 - 5 - test "===" do 6 - object = -> { "hello" } 7 - 8 - assert _Unit(object) === object 9 - refute _Unit(object) === -> { "hello" } 10 - end 11 - 12 - test "hierarchy" do 13 - object = "a" 14 - 15 - assert_subtype _Unit(object), _Unit(object) 16 - refute_subtype _Unit(object), _Unit(+"a") 17 - end