CodeSampleX

サンプル

sorbet-runtime 0.6.13427: Demonstrate that T::Struct silently ignores unknown attributes at runtime

検証済みサンプル — gem sorbet-runtime 0.6.13427: Demonstrate that T::Struct silently ignores unknown attributes at runtime. ruby 3 · linux alpine/x64 · docker で…

sha256:2851081928106c445173fdcf82af94358ca1925ee488774a2d51188aa81a9c83

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
2
ビルドした署名鍵
1
宣言された環境 ruby linux x64 ruby ruby bundler

検証実行環境

環境 コントラクト ステージ 実行日
ruby 3 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · rubygems@1
2026-08-16
ruby 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · rubygems@1
2026-08-18

ケース

HOW
ゴール
Demonstrate that T::Struct silently ignores unknown attributes at runtime
パッケージ
シンボル
  • T::Struct
環境
ruby
作成日
2026-08-16T17:12:48Z

コントラクト

  1. Initializing a T::Struct with an unknown attribute raises ArgumentError

ファイル

  • Gemfile
  • csx.json
  • test/contract.rb
  • test/enum_contract.rb

ソースアーティファクトをダウンロード (tar.gz)

ソース

Gemfile
source "https://rubygems.org"

gem "sorbet-runtime", "0.6.13427"
csx.json
{"case":{"believed":"Initializing a T::Struct with an undeclared attribute is silently ignored at runtime","caseId":"case:sha256:1ea93861194969aa6b61592a8dc4dd4a247614e535969fd64441a668426279a0","contract":["Initializing a T::Struct with an unknown attribute raises ArgumentError"],"goal":"Demonstrate that T::Struct silently ignores unknown attributes at runtime","kind":"HOW","packages":["pkg:gem/sorbet-runtime@0.6.13427"],"schemaVersion":1,"symbols":["T::Struct"]},"contractCommand":["ruby","test/contract.rb"],"environment":{"arch":"x64","ecosystem":"gem","executionContext":"ruby","language":"ruby","os":"linux","packageManager":"bundler","runtime":"ruby","schemaVersion":1},"license":"MIT-0","packages":["pkg:gem/sorbet-runtime@0.6.13427"],"schemaVersion":1,"symbols":["T::Struct"],"verifierAdapter":"rubygems@1"}
test/contract.rb
require 'sorbet-runtime'

class Person < T::Struct
  const :name, String
  const :age, Integer
end

begin
  Person.new(name: "Alice", age: 30, unknown: "value")
  # If no error, contract fails
  puts "FAIL: No error raised"
  exit 1
rescue ArgumentError => e
  # Expected error for unknown attribute
  puts "PASS"
  exit 0
end
test/enum_contract.rb
require 'sorbet-runtime'
require 'json'

class Color < T::Enum
  enums do
    Red = new
    Green = new
    Blue = new
  end
end

value = Color::Red
begin
  json = JSON.dump(value)
  if json == "\"red\""
    puts "PASS"
    exit 0
  else
    puts "FAIL: Unexpected JSON output #{json}"
    exit 1
  end
rescue => e
  puts "FAIL: Exception #{e}"
  exit 1
end

オリジンシーダー

csx-seed