Functions you didn't know existed

view full story

http://ubuntuforums.org – Well, today I found something out pretty cool. I had no idea that Ruby did pattern matching, though I've seen it in OCaml, Erlang and Haskell. Code: ["John", 1, 3, nil, "Jane"].each do |x|   case x   when String     puts "Hello #{x}!!"   when Integer   puts x + 2   else     puts "Sorry!!"   end end ["a", "b", "c", "d"].each { |x|   case x   when "a" then puts "A"   when "b" then puts "B"   when & (Hardware)