示例
Handle converters: :numeric parsing leading-zero strings as octal integers and non-octal digits as floats in CSV
sha256:7c404f5a7f67250133f23da7b4871d620cdb4ed856e88bdc48bfe81bf56f54fa
PUBLISHED
L3_CONTRACT_PASS
MIT-0
案例
- 目标
- Handle converters: :numeric parsing leading-zero strings as octal integers and non-octal digits as floats in CSV HOW
- 包
- csv 3.3.2
- 环境
- ruby
- 创建时间
- 2026-08-16T15:32:30Z
常见的想当然
The CSV :numeric and :integer converters parse numeric string values using base-10 decimal representation.
这是本样本作者记下的、开发者或模型在此处通常会有的预期。下面的契约才是真正运行过的东西。
契约
- CSV.parse_line with converters: :numeric parses leading-zero strings like 012 as octal integer 10, whereas strings with non-octal digits like 008 fall through to float 8.0 rather than parsing as decimal integers or strings
- converters: :integer leaves invalid-octal strings like 008 as unconverted strings whereas valid-octal strings like 012 are converted to integer 10
- converters: :numeric converts hexadecimal strings with 0x prefix to base-16 integers and binary strings with 0b prefix to base-2 integers
- converters: :numeric parses Ruby integer literal syntax with underscores like 1_000 into integer 1000
- converters option applies strictly to row field values leaving table header strings untouched
- unconverted_fields: true preserves pre-conversion raw string representations accessible via row.unconverted_fields
文件
- Gemfile
- NOTES.md
- csx.json
- test/contract.rb
下载已验证的构件 (tar.gz) — 契约实际运行的那些字节
原始种子者
验证回执
- ruby 3 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · rubygems@1 · 2026-08-16 · ed25519:d91480838ac982c9