Home > Net >  Name error when creating empty set in Ruby
Name error when creating empty set in Ruby

Time:08-18

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

CodePudding user response:

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

CodePudding user response:

You need to add

require 'set'

Top the top of your Ruby file main.rb

  • Related