Using Collections in Ruby

I am creating a simple Ruby on Rails plugin and I am considering using the Set class. I don’t see that the Set class is used too often in other people's code.

Is there a reason people prefer to use (subclasses) of an array rather than a set? Will using a kit introduce problems with certain problems for some people?

+4
source share
3 answers

Set is part of the standard library, so it should not create dependency problems. If this is the cleanest way to solve the problem, go for it.

Regarding the use (or lack thereof), I think there are probably two main reasons:

  • programmers not familiar with the library
  • programmers do not understand when sets are the best way to solve.
  • programmers who don't know / don't remember anythign about sets at all.

Make three main reasons.

+8
source

In any case, Ruby arrays are very flexible, there are many methods that can threaten it, for example, as a collection, stack or queue.

+2
source

As I understand it from what I read here, it is that Set are likely mathematical sets, i.e. the order does not matter and is not preserved.

In most software applications, if you are not doing math, this is limited use, because usually you want to keep order.

0
source

All Articles