Number multiplication in Ruby returning string concatenation instead of integer product -


the following code double number not working expected. e.g., if input 5, returning 55 instead of 10.

# program double number taken user input using user defined method     def double (x)   puts("lets yield!")   yield x * 2 end  puts "enter number want double : " x = gets.chomp  double (x) { |n| puts n } 

because using * method on string. convert x integer.

x = gets.chomp.to_i 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -