Skip to content

Instantly share code, notes, and snippets.

@shostakovich
Created August 22, 2012 17:42
Show Gist options
  • Save shostakovich/3427847 to your computer and use it in GitHub Desktop.
Save shostakovich/3427847 to your computer and use it in GitHub Desktop.
Nice stuff on set
require 'set'
Set.new([1, 2, 3])
#<Set: {1, 2, 3}>
Set.new([1, 2, 3]) do |val| val * 2 end
#<Set: {2, 4, 6}>
Set.new([1,2,3]) & Set.new([2,3,4])
#<Set: {2, 3}>
Set.new([1,2,3]) - Set.new([2,3])
#<Set: {1}>
Set.new([1,2,3]) | Set.new([2,3,4])
#<Set: {1, 2, 3, 4}>
Set.new([1,2,3]) ^ Set.new([2,3,4])
#<Set: {4, 1}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment