1: require 'set'2:3: mySet = Set.new ["Orange","Banana","Kivy"]4:5: mySet.each {|nextFruit| puts nextFruit}6:7: puts mySet.inspect8:9: puts "Done"
Returns:
Orange
Banana
Kivy
#<Set: {"Orange", "Banana", "Kivy"}>
Done
Dividing the set into smaller set by condition
1: require 'set'2:3: mySet = Set.new ["Orange","Banana","Kivy","Limon","Mango"]4:5: dsets = mySet.divide { |fr1,fr2| fr1.length == fr2.length }6:7: dsets.each {|nextSet| puts nextSet.inspect}8:9: puts "Done"
Returns
I:\Learn\Ruby>myRuby7
#<Set: {"Orange", "Banana"}>
#<Set: {"Kivy"}>
#<Set: {"Limon", "Mango"}>
Done
אין תגובות:
הוסף רשומת תגובה