Flowdock

Notes posted by Overbryd

RSS feed
February 24, 2009
0 thanks

Test if one array includes the elements of another

Recently I’ve written this little snippet:

puts "yay" if [1, 2, 3].each {|i| break unless (1..9).to_a.include?(i)}
# => "yay"

puts "nope" unless [1, 2, 3, 'A'].each {|i| break unless (1..9).to_a.include?(i)}
# => "nope"