Skip to content
instance method

Set#inspect

() -> ::String
inspect → new_string

Returns a new string containing the set entries:

Example
s = Set.new
s.inspect # => "Set[]"
s.add(1)
s.inspect # => "Set[1]"
s.add(2)
s.inspect # => "Set[1, 2]"

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.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0