Sample
set 1.1.1: Handle Set constructor block transforms, Enumerable#map return types, in-place filter nil returns, and add/delete predicate return shapes
Verified sample for gem set 1.1.1: Handle Set constructor block transforms, Enumerable#map return types, in-place filter nil returns, and add/delete…
sha256:488c31c9c5aeae5ae9230e7887ebe9b551c80495e0cd328e83d61761cfce85e7
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 2
- Signing keys that built it
- 2
Declared environment
ruby linux x64 ruby ruby rubygems
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| ruby 3 · linux debian/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · rubygems@1 |
2026-08-17 |
| ruby 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · rubygems@1 |
2026-08-18 |
Case
HOW- Goal
- Handle Set constructor block transforms, Enumerable#map return types, in-place filter nil returns, and add/delete predicate return shapes
- Packages
- Symbols
-
- Set.new
- Set#map
- Set#map!
- Set#select!
- Set#reject!
- Set#add
- Set#add?
- Set#delete
- Set#delete?
- Set#flatten
- Set#===
- Environment
- ruby
- Created
- 2026-08-17T02:46:10Z
Contract
- assert Set.new with a block transforms each element before insertion rather than filtering elements, inserting the boolean return values
- assert Set#map returns an Array that preserves duplicates and lacks Set methods, while in-place map! mutates the receiver into a Set
- assert Set#select! and Set#reject! return nil when no elements are removed rather than returning the receiver
- assert Set#add always returns self even for duplicates, whereas Set#add? returns self on addition and nil on duplicate
- assert Set#delete returns self unconditionally, whereas Set#delete? returns nil when the element is absent
- assert Set#flatten only unpacks nested Set instances, leaving nested Array instances intact
- assert Set#=== tests element inclusion for pattern matching, while Set equality with Array is always false
Files
- Gemfile
- Gemfile.lock
- NOTES.md
- csx.json
- test/contract.rb
Source
source "https://rubygems.org"
gem "set", "1.1.1"
gem "minitest", "5.27.0"
GEM
remote: https://rubygems.org/
specs:
minitest (5.27.0)
set (1.1.1)
PLATFORMS
ruby
x64-mingw-ucrt
DEPENDENCIES
minitest (= 5.27.0)
set (= 1.1.1)
CHECKSUMS
bundler (4.0.18) sha256=02d9a17429de1847b4e0c9f27a9ee4b20c0a74c0a641b4e77195d6019e3618ac
minitest (5.27.0) sha256=2d3b17f8a36fe7801c1adcffdbc38233b938eb0b4966e97a6739055a45fa77d5
set (1.1.1) sha256=6c7ac6c06d5907216395a4d5dae3ffe52ca5ee8a372befe6d4dea794383f98f0
BUNDLED WITH
4.0.18
# Set API Patterns and Return Semantics
## Prior Search Findings
The search query for `pkg:gem/set` returned existing sample `sha256:7a622d8fbf61d9ccea9796f655d24afc226f861f933bc616c92ec7ee61ee448a`, which addresses Ruby standard library gem extraction schedules and element hash mutation. This sample targets the core API traps of `Set` methods: block transform semantics in constructors, return types of transformation methods, `nil` returns from unmodified in-place filters, and return values of membership manipulation methods.
## Failure Modes
- `Set.new(enum) { |x| condition }` fails silently with a green build by populating the set with booleans (`[true, false]`) rather than filtering elements, corrupting downstream logic and collection sizes.
- `Set#map` fails loudly at runtime with `NoMethodError` when callers chain Set operations onto the returned `Array`, or fails silently by retaining duplicate elements.
- `Set#select!` / `Set#reject!` fails loudly with `NoMethodError` on `nil:NilClass` when chained or reassigned if no elements matched the removal criteria.
- `Set#add(x)` fails silently when used in conditional branching expecting `false` on duplicate items, as `#add` always returns truthy `self` whereas `#add?` returns `nil` on duplicates.
- `Set#flatten` fails silently by leaving nested `Array` instances untouched because it only unpacks instances of `Set`.
{"case":{"believed":"Passing a block to Set.new filters matching elements, Set#map preserves the Set type with duplicate elimination, in-place filters always return the receiver, and Set#add returns a boolean indicating whether insertion occurred.","caseId":"case:sha256:09fce3468fa2699b6ec8bdbb2adff8844acb591a1098b4af44864aaf1a90aac1","contract":["assert Set.new with a block transforms each element before insertion rather than filtering elements, inserting the boolean return values","assert Set#map returns an Array that preserves duplicates and lacks Set methods, while in-place map! mutates the receiver into a Set","assert Set#select! and Set#reject! return nil when no elements are removed rather than returning the receiver","assert Set#add always returns self even for duplicates, whereas Set#add? returns self on addition and nil on duplicate","assert Set#delete returns self unconditionally, whereas Set#delete? returns nil when the element is absent","assert Set#flatten only unpacks nested Set instances, leaving nested Array instances intact","assert Set#=== tests element inclusion for pattern matching, while Set equality with Array is always false"],"goal":"Handle Set constructor block transforms, Enumerable#map return types, in-place filter nil returns, and add/delete predicate return shapes","kind":"HOW","packages":["pkg:gem/set@1.1.1"],"schemaVersion":1,"symbols":["Set.new","Set#map","Set#map!","Set#select!","Set#reject!","Set#add","Set#add?","Set#delete","Set#delete?","Set#flatten","Set#==="]},"contractCommand":["ruby","test/contract.rb"],"environment":{"arch":"x64","ecosystem":"gem","executionContext":"ruby","language":"ruby","os":"linux","packageManager":"rubygems","runtime":"ruby","schemaVersion":1},"license":"MIT-0","packages":["pkg:gem/set@1.1.1"],"schemaVersion":1,"symbols":["Set.new","Set#map","Set#map!","Set#select!","Set#reject!","Set#add","Set#add?","Set#delete","Set#delete?","Set#flatten","Set#==="],"verifierAdapter":"rubygems@1"}
require "minitest/autorun"
require "set"
class SetApiContractTest < Minitest::Test
def test_set_new_block_transforms_elements_instead_of_filtering
# Naive assumption: Set.new(enum) { |x| condition } filters elements like select/filter
# Reality: The block transforms each element before insertion (map), inserting the return value
result = Set.new([1, 2, 3, 4]) { |n| n.even? }
assert_equal Set[false, true], result
assert_equal 2, result.size
refute_includes result, 2
refute_includes result, 4
assert_includes result, true
assert_includes result, false
end
def test_set_map_returns_array_losing_set_uniqueness_and_methods
# Naive assumption: Set#map returns a Set
# Reality: Set#map is inherited from Enumerable and returns an Array, preserving duplicates
words = Set["apple", "banana", "apricot"]
mapped = words.map { |word| word[0] }
assert_instance_of Array, mapped
assert_equal ["a", "a", "b"], mapped.sort
assert_equal 3, mapped.size
assert_raises(NoMethodError) { mapped.subset?(Set["a", "b", "c"]) }
# In-place map! mutates receiver, preserves Set class, and collapses duplicates
words.map! { |word| word[0] }
assert_instance_of Set, words
assert_equal Set["a", "b"], words
assert_equal 2, words.size
end
def test_inplace_filters_return_nil_when_no_elements_are_removed
# Naive assumption: Set#select! / Set#reject! always returns self for chaining
# Reality: When no changes are made, select!/reject! returns nil (like Array#select!)
set = Set[1, 2, 3]
# No elements removed -> returns nil
result = set.select! { |x| x > 0 }
assert_nil result
assert_equal Set[1, 2, 3], set
# Elements removed -> returns self
mutated = set.select! { |x| x.odd? }
assert_same set, mutated
assert_equal Set[1, 3], set
end
def test_add_and_delete_return_semantics_differ_from_boolean_predicates
# Naive assumption: Set#add returns a boolean or Set#add? returns boolean true/false
# Reality: #add always returns self (truthy); #add? returns self if added or nil if duplicate
set = Set[:read]
# add returns self unconditionally
assert_same set, set.add(:read)
assert_same set, set.add(:write)
# add? returns self when newly added, nil when already present
assert_same set, set.add?(:exec)
assert_nil set.add?(:read)
# delete returns self unconditionally; delete? returns self or nil
assert_same set, set.delete(:nonexistent)
assert_same set, set.delete?(:exec)
assert_nil set.delete?(:nonexistent)
end
def test_flatten_only_flattens_nested_sets_not_nested_arrays
# Naive assumption: Set#flatten unpacks all nested collections (Sets and Arrays)
# Reality: Set#flatten only unpacks instances of Set; nested Arrays remain intact
set_with_sets = Set[1, Set[2, 3]]
assert_equal Set[1, 2, 3], set_with_sets.flatten
set_with_arrays = Set[1, [2, 3]]
flattened_arrays = set_with_arrays.flatten
assert_equal Set[1, [2, 3]], flattened_arrays
assert_includes flattened_arrays, [2, 3]
refute_includes flattened_arrays, 2
end
def test_case_equality_and_array_comparisons
# Set#=== checks element inclusion for case/when pattern matching
allowed_roles = Set[:admin, :superadmin]
assert allowed_roles === :admin
refute allowed_roles === :guest
refute :admin === allowed_roles
role = :admin
matched = case role
when allowed_roles then :authorized
else :unauthorized
end
assert_equal :authorized, matched
# Set#== with Array is always false even if elements match
refute_equal Set[1, 2], [1, 2]
assert_equal Set[1, 2], Set[2, 1]
end
end