0

I'm trying to use the Set class from the standard Ruby library. I am creating an empty Set like so:

Set.new

but then I end up with this error:

main.rb:36:in `<main>': uninitialized constant Set (NameError)

Set.new
^^^

How do I properly create an empty instance of Set

CJG
  • 457
  • 2
  • 17
  • 2
    Does this answer your question? [Uninitialized constant error in Ruby class](https://stackoverflow.com/questions/29133040/uninitialized-constant-error-in-ruby-class) – Dennis Kozevnikoff Aug 17 '22 at 22:32
  • 1
    @DennisKozevnikoff It's not quite the same, because it is class from (not core) standard library. Your link is about some developed class – mechnicov Aug 17 '22 at 22:49

2 Answers2

6

Set is standard Ruby class, but you need to require it just like any other class / module from the standard library (like JSON, Date, Timeout, etc.)

You need to add to the top of your main.rb

require 'set'

You can see it in the examples in the official docs

mechnicov
  • 12,025
  • 4
  • 33
  • 56
2

You need to add

require 'set'

Top the top of your Ruby file main.rb

Scott Milella
  • 468
  • 5
  • 10