From: "Peña, Botp" Date: 2008-05-27T13:57:21+09:00 Subject: Re: string+char, cant convert nil, but not nil From: notnorwegian@yahoo.se [mailto:notnorwegian@yahoo.se] # tryong to do a ROT13(http://en.wikipedia.org/wiki/Rot_13) encrypter/ # decrypter. # x = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" # y = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm" # arr = x.split(//).zip(y.split(//)) # dict = Hash[*arr.flatten] # puts "Input phrase: " # phrase = gets if you tried this in irb, you'd see the value of phrase. hint: gets also stores the (unwanted) ending char (chomp the newline pls :) # rotated = "" # for x in (0..phrase.length()-1) # rotated = rotated + dict[phrase[x].chr] # end # puts rotated # # '+' cant convert nil into string # cant convert nil into string that's the effect dict["\n"] #=> nil btw, in ruby, there are many ways to skin that rot13 problem. eg, "testing".tr('A-MN-Za-mn-z','N-ZA-Mn-za-m') #=> "grfgvat" kind regards -botp