I have a method which takes 2-arguments - message to print on the screen and (default) value. If the default value is nil then I want just the message to be printed on the screen otherwise message should contain the default value in square brackets.
For example: If I pass method1("Hello" , ""), it should print Hello but if I pass method1("Hello", "User"), it should print Hello [User]:. But right now it printing only Hello even in second scenario.
Below is the piece of my code:
def method1(mes, value)
val = ""
begin
if value == "" || "#{value}".to_i == 0
val = ask(mes) do |ch|
ch = true
end
else
val = ask(message+" [#{value}]: ") do |ch|
ch = true
end
end
if val == "" then
val = "#{value}"
end
rescue => e
print "Except occured in method1(#{mes}, #{value}) "+e
end
return val
end
"#{value}".to_iare usually pointless, asvalue.to_iwould do the job here.