Read input from console in Ruby?

前端 未结 5 673
孤独总比滥情好
孤独总比滥情好 2020-12-23 02:50

I want to write a simple A+B program in ruby, but I have no idea how to work with the console.

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-23 03:29

    if you want to hold the arguments from Terminal, try the following code:

    A = ARGV[0].to_i
    B = ARGV[1].to_i
    
    puts "#{A} + #{B} = #{A + B}"
    

提交回复
热议问题