Skip to content

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

instance method

Set#inspect

() -> ::String
inspect → string

Returns a string representation of self:

Example
Set[*%w[foo bar], {foo: 0, bar: 1}].inspect
# => "Set[\"foo\", \"bar\", {foo: 0, bar: 1}]"

Related: see Methods for Converting.

Ruby version changes

  1. 4.0
    • Set#inspect now uses a simpler display, similar to literal arrays. (e.g., Set[1, 2, 3] instead of #<Set: {1, 2, 3}>). [Feature #21389]

See also #init_with #intersect? #include? #intersection also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0