Mega Code Archive

 
Categories / Ruby / Collections
 

Create set with Set new

require 'set' p Set.new(1..5)              # => #<Set: {5, 1, 2, 3, 4}> p Set.new([1,2,3])           # => #<Set: {1, 2, 3}> p Set.new([1,2,3]) {|x| x+1} # => #<Set: {2, 3, 4}>