f = -> s {[''].product(*s.chars.map {|c| [c, c.upcase]}).map(&:join)}p %W(#{} a ab).map {|s| [s, f.(s)]}
Standard input is empty
[["", [""]], ["a", ["a", "A"]], ["ab", ["ab", "aB", "Ab", "AB"]]]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!