と呼ばれる単一のファイルがありますExercises.rb
def ask(prompt)
print prompt, ' '
$stdout.flush
s = gets
return s
end
def myreverse(s)
aux=""
for i in 0..s.length-1
aux=s[i] + aux
end
return aux
end
def mywordreverse(s)
aux=[]
s=s.split(" ")
for i in 0..s.length-1
aux.unshift(s[i])
end
return aux.join(" ")
end
def choose(s,option)
case option
when 1 then print myreverse(s)
when 2 then print mywordreverse(s)
when 3 then print "hello"
else print "You gave me #{option} -- I have no idea what to do with that."
end
end
s=ask("Write a string to reverse: ")
option=ask("Choose an option. 1 - Reverse string. 2 - Reverse String words : ")
choose(s,option)
You gave MYCHOSENOPTION -- I have no idea what to do with that.
どのオプションを選択しても、常に取得しています。if
比較する 1 の直前にa を付けるとcase
、オプションが文字列に一致していないように見えます。