当前位置:首页>开发>正文

ruby编程实例案例可以编什么程序

2023-04-17 23:16:01 互联网 未知 开发

 ruby编程实例案例可以编什么程序

ruby编程实例案例可以编什么程序

使用SciTE, or RadRails, or Eclipse编辑:

1. 计算器:
puts "Please input Number1:"
number1 = gets
puts "Please input a operator( ,-,*,/):"
op = gets
puts "Please input Number2:"
number2 = gets
case op.chomp
when " "
result = number1.to_i number2.to_i
when "-"
result = number1.to_i - number2.to_i
when "*"
result = number1.to_i * number2.to_i
when "/"
result = number1.to_i / number2.to_i
end
puts "Result: #{number1.chomp} #{op.chomp} #{number2.chomp} = #{result}"
====================================================================================
2.在项目中访问变量:
$qj="We can see the social progressing from the following phenomenon:"
class TestCL
CHANGE = "In changing..."
before = "We are living in the grass house"
now = "We are living in the tall buildings"
future = "We are living in the sky buildings"
puts CHANGE " " $qj " before : " before " now :" now " future :" future
end

随便看看