Ruby 3 · Errors and files

Use a Set

A collection of unique values with fast membership tests.

require "set"

seen = Set.new
seen << 1 << 2 << 1
puts seen.size

Official Ruby 3 documentation

More errors and files commands

All errors and files commands · Ruby 3 cheatsheet

Was this page helpful?