puts,print,echo,BEGIN,END,#{ expr },数组的使用
进入rb文件里面开始编写程序
# vi rubytest.rb
puts "Hello, Ruby!";
print <<show # 与puts输出的结果相同
I am wang,
and who are you?
show
print <<'EOC'; # 同上
echo I here
EOC
BEGIN { # begin语法里面的code会在程序开始执行
puts "the begin text"
}
运行结果
END{ # END语法里面的code会在程序结束前执行
puts "the begin text"
}
BEGIN { # begin语法里面的code会在程序开始执行
puts "the begin text"
}
运行结果
数据类型输出
#整型 Integer 以下是一些整型字面量
#字面量:代码中能见到的值,数值,bool值,字符串等都叫字面量
num1 =0;
num2 =100000;
num3 =1_000_000;
puts num1;
puts num2;
puts num3;
运行结果
#{ expr }
name ="wang";
puts name;
puts "#{name} use \#name";
运行结果
创建数组
this
is
a
array
[3.3.3.3]