one = 1
int = 1
float = 3.14159265
str = "This is a String"
str = 'This is a String too'
p "Hellow World"
print "Hellow World"
# 注释行以#开头
=begin
注释行1
注释行2
=end
a = 3
#加法
p a + 1
#减法
p a - 1
#乘法
p a * 1
#阶乘
p a**2
#除法
p a / 3
#余除
p a % 3
empty = nil
bool = true
bool = false
a = 1
b = 2
#相等?
p a == b
#a大于b?
p a > b
#a小于b?
p a < b
#a小于或等于b?(a 不超过 b?)
p a <= b
#a大于或等于b?(a 超过 b?)
p a >= b
a = 1
b = 2
if a > b
p "a 大于 b"
elsif a < b
p "a 小于 b"
else
p "a 等于 b"
end
a = 1
case a
when 1
p "a == 1"
when 2
p "a == 2"
else
p "a == 其他值"
end
array = [1,2,3,4]
obj = Object.new
p obj
hash = {1=>"one",2=>"two"}
p hash
class CLS
end
def method
end
local_var = "局部变量"
$global_var = "全局变量"
@insta_var = "实例变量"
@@class_var = "类变量"
CONSTA = "常量"
a = 1
loop do
p a += 1
break if a == 5
end
for a in 0...5
p a
end
a = 1
while a < 5
p a += 1
end
ar = Array.new
ar.push 1
p ar
def method(var)
p var
end
method(1)
exit
module MOD
end
class Father
end
class Son < Father
end
module MOD_A
end
class CLS
include MOD_A
end
module MOD
CONSTA = 1
end
module CLS
CONSTA = 2
end
p MOD::CONSTA
p CLS::CONSTA
class CLS_lv1
class CLS_lv2
class CLS_lv3
end
end
end
module MOD
class CLS
end
end
p obj = CLS_lv1::CLS_lv2::CLS_lv3.new
p obj = MOD::CLS
class CLS
attr_reader :info
attr_writer :content
attr_accessor :data
end
obj = CLS.new
obj.content = 1
obj.data = 1
p obj.info
p obj.data
def method_1
p 1
end
alias method_2 method_1
method_2
def method
return 1
end
def call_back(var)
p var
end
call_back( method )
[1,2,3,4].each do |i|
p i
end
a = 1;
p a;
bool = true
if bool then p true else p false end
p bool ? true : false
class Father
def method
p "ori"
end
end
class Son < Father
def method
super
end
end
hour = 1; min = 2; sec = 3
p sprintf("%02d:%02d:%02d", hour, min, sec)
symbol = :sym
reg = /\w\d\n*/
rand_num = rand(100)
script = "p 1"
eval(script)
time = Time.now
begin
p nil + 1
rescue
p 1
end
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |