[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

string+char, cant convert nil, but not nil

slix

5/27/2008 4:28:00 AM

tryong to do a ROT13(http://en.wikipedia.org/w...) encrypter/
decrypter.

x = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
y = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"
arr = x.split(//).zip(y.split(//))
dict = Hash[*arr.flatten]

puts "Input phrase: "
phrase = gets

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



puts dict[phrase[2].chr] works though...
3 Answers

Peña, Botp

5/27/2008 4:57:00 AM

0

From: notnorwegian@yahoo.se [mailto:notnorwegian@yahoo.se]=20
# tryong to do a ROT13(http://en.wikipedia.org/w...) encrypter/
# decrypter.
# x =3D "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
# y =3D "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"
# arr =3D x.split(//).zip(y.split(//))
# dict =3D Hash[*arr.flatten]
# puts "Input phrase: "
# phrase =3D gets

if you tried this in irb, you'd see the value of phrase.=20
hint: gets also stores the (unwanted) ending char=20
(chomp the newline pls :)

# rotated =3D ""
# for x in (0..phrase.length()-1)
# rotated =3D rotated + dict[phrase[x].chr]
# end
# puts rotated
#=20
# '+' cant convert nil into string
# cant convert nil into string

that's the effect

dict["\n"]
#=3D> 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')
#=3D> "grfgvat"

kind regards -botp





trotsky

3/10/2014 2:03:00 PM

0

On 3/10/14 5:44 AM, NoBody wrote:
> On Sun, 09 Mar 2014 12:32:13 -0500, trotsky <gmsingh@email.com> wrote:
>
>> On 3/9/14 9:36 AM, NoBody wrote:
>>> On Sat, 08 Mar 2014 09:44:59 -0600, trotsky <gmsingh@email.com> wrote:
>>>
>>>> On 3/7/14 9:38 AM, BTR1701 wrote:
>>>>> In article <fM2dnVSTE4RQI4TOnZ2dnUVZ_hydnZ2d@mchsi.com>,
>>>>> trotsky <gmsingh@email.com> wrote:
>>>>>
>>>>>> On 3/6/14 7:23 PM, BTR1701 wrote:
>>
>>>>>>> Other than the fact that she predicted exactly what happened**, you
>>>>>>> might have a point.
>>>>>>
>>>>>>
>>>>>> Interesting. What, pray tell, is the significance of that stupid cow,
>>>>>> then?
>>>>>
>>>>> The significance is that you smug condescending leftists aren't nearly
>>>>> as smart as you think you are.
>>>>
>>>>
>>>> So you can't answer the question.
>>>
>>> Actually he did. Your lack of comprehension is so noted.
>>
>>
>> No, that's not correct. Wanna try again?
>
> Thank you for demonstrating your inability to comprehend yet again.


Hey, if it helps you believe your own lie I say you go with that.

Antonio E. Gonzalez

3/11/2014 6:15:00 AM

0

On Thu, 06 Mar 2014 17:23:19 -0800, BTR1701 <atropos@mac.com> wrote:

>In article <rsedh9trg3kahhvib9avedgehlv41am0rv@4ax.com>,
> Antonio E. Gonzalez <AntEGM111@aol.com> wrote:
>
>> On Mon, 03 Mar 2014 23:39:22 -0800, BTR1701 <atropos@mac.com> wrote:
>>
>> >In article <mcuah9ptsljq3tbm9ujb2jebr4bc3kk87v@4ax.com>,
>> > Antonio E. Gonzalez <AntEGM111@aol.com> wrote:
>> >
>> >> On Mon, 03 Mar 2014 19:35:46 -0800, BTR1701 <atropos@mac.com> wrote:
>> >>
>> >>
>> >> >http://www.youtube.com/watch?v=C...
>> >> >
>> >> >
>> >> It says a lot when even a conservative like Chris "Tingles"
>> >> Matthews calls out your foreign policy mistakes.
>
>> >> Oh, and considering Russia's issue is only with Ukraine (dating
>> >> back to the 1930s), Romney is still wrong.
>> >
>> > Palin sure wasn't, which is why you snipped that bit completely
>> > out. Doesn't quite fit your narrative, does it?
>>
>> Actually, she was even more wrong.
>
>Other than the fact that she predicted exactly what happened**, you
>might have a point.
>

Nope, not even close.

>
>
>**And then was relentlessly mocked by smug assholes like yourself who
>thought they knew better.

We do know better, hence why she's historical debris.



--

- ReFlex76

- <http://twitter.com/Re...