Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Gem::Platform#deconstruct_keys

deconstruct_keys(keys)

Deconstructs the platform into a hash for pattern matching. Returns a hash with keys :cpu, :os, and :version.

Example
Gem::Platform.new("x86_64-darwin-20").deconstruct_keys(nil)
#=> { cpu: "x86_64", os: "darwin", version: "20" }

This enables hash pattern matching:

Example
case Gem::Platform.new("x86_64-linux")
in cpu: "x86_64", os: "linux"
  # Matches Linux on x86_64
end