r/ruby • • 21h ago

Question So much knowledge in one joke

Post image
15 Upvotes

r/ruby • • 22h ago

Ruby Users Forum Wrapped 2026

Thumbnail
rubyforum.org
5 Upvotes

r/ruby • • 1h ago

um CLI modular OSINT & superfície de ataque com um console interativo e relatórios HTML locais

Post image
2 Upvotes

r/ruby • • 3h ago

AcceptLanguage 3.0: one method, bounded parsing, and a written spec

1 Upvotes

I posted here about accept_language 2.2 earlier this year. Version 3.0 is out, and it is a breaking release, so here is what changed and why.

One entry point. parse and match are gone. There is a single method now:

# 2.x
AcceptLanguage.parse(header).match(:en, :fr)

# 3.0
AcceptLanguage.negotiate(header, %i[en fr])

It takes the header value (or nil) and an Array of Symbols or Strings, and returns the best match exactly as you gave it, or nil.

Bounded work on client input. The header comes from the client, so the library now limits what it does with it: a field longer than 4096 bytes is treated as absent, and only the first 50 elements are considered. In 2.x, a 1 MB header took seconds to process.

No header makes it raise. A header with invalid encoding (a UTF-8 String holding 0xFF, say) used to raise ArgumentError. The field is now handled as bytes. Case folding is ASCII-only too: U+212A KELVIN SIGN is no longer read as k.

A few results change. When several ranges match a tag, the most specific one now decides its q-value:

AcceptLanguage.negotiate("en-US, en;q=0", %i[en-US])
# => :"en-US" (was nil)

AcceptLanguage.negotiate("en;q=0.9, en-US;q=0.5", %i[en-US en-GB])
# => :"en-GB" (was :"en-US")

This only matters when a header lists a range and one of its prefixes with different q-values. Duplicate ranges and malformed elements (en;q=, e n) also have a defined behavior now; the changelog lists each case.

A specification and shared test vectors. The behavior is written down in SPECIFICATION.md, with test vectors in a TSV file. The Elixir port implements the same spec and passes the same vectors.

Ruby 3.3+ is required. Still zero dependencies.

  • GitHub: https://github.com/cyril/accept_language.rb
  • Changelog: https://github.com/cyril/accept_language.rb/blob/main/CHANGELOG.md

Feedback welcome, especially on the matching rule change.