This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.
Generating a Succession of Strings | ||
---|---|---|
Code | Expected | Actual |
('aa'..'ag').each { |x| puts x } |
aa ab ac ad ae af ag |
aa ab ac ad ae af ag |
def endless_string_succession(start) while true yield start start = start.succ end end endless_string_succession('fol') do |x| puts x break if x[-1] == x[-2] end |
fol fom fon foo |
fol fom fon foo |
'89999'.succ |
"90000" | "90000" |
'nzzzz'.succ |
"oaaaa" | "oaaaa" |
'Zzz'.succ |
"AAaa" | "AAaa" |
'z'.succ |
"aa" | "aa" |
'aa'.succ |
"ab" | "ab" |
'zz'.succ |
"aaa" | "aaa" |
'AA'.succ |
"AB" | "AB" |
'AZ'.succ |
"BA" | "BA" |
'ZZ'.succ |
"AAA" | "AAA" |
'aZ'.succ |
"bA" | "bA" |
'Zz'.succ |
"AAa" | "AAa" |
'foo19'.succ |
"foo20" | "foo20" |
'foo99'.succ |
"fop00" | "fop00" |
'99'.succ |
"100" | "100" |
'9Z99'.succ |
"10A00" | "10A00" |
'10-99'.succ |
"11-00" | "11-00" |
'a-a'.succ |
"a-b" | "a-b" |
'z-z'.succ |
"aa-a" | "aa-a" |
'Hello!'.succ |
"Hellp!" | "Hellp!" |
%q{'zz'}.succ |
"'aaa'" | "'aaa'" |
%q{z'zz'}.succ |
"aa'aa'" | "aa'aa'" |
'$$$$'.succ |
"$$$%" | "$$$%" |
s = '!@-' 13.times { puts s = s.succ } |
!@. !@/ !@0 !@1 !@2 ... !@8 !@9 !@10 |
!@. !@/ !@0 !@1 !@2 !@3 !@4 !@5 !@6 !@7 !@8 !@9 !@10 |
("a".."e").to_a.reverse_each { |x| puts x } |
e d c b a |
e d c b a |