!/usr/bin/ruby
puts “———–Ruby 数据类型”
puts “Ruby支持的数据类型包括基本的Number、String、Ranges、Symbols,以及true、false和nil这几个特殊值,同时还有两种重要的数据结构——Array和Hash。”
puts “\n———————-Array\n”
ary = [[ “liqiang”, 8.20, ],[ “liqiang” ]]
ary.each do |i|
i.each do |j|
puts j
end
puts “———–”
end
puts “\n———————-Hash\n”
hsh = colors = { “red” => 0xf00, “green” => 0x0f0, “blue” => 0x00f }
hsh.each do |key, value|
puts key, ” is “, value, “\n”
end
puts “\n———————-范围类型\n”
(10..15).each do |n|
puts n, ’ ’
end
puts “\n———————-范围类型\n”
(10…15).each do |n|
puts n, ’ ’
end
puts “\n———————- { expr } 替换任意 Ruby 表达式的值为一个字符串。在这里,expr 可以是任意的 Ruby 表达式\n”
puts “相乘 : {24*60*60}”;
puts “\n———————-\n”
name=”Ruby”
puts name
puts “{name+”,ok”}”
puts “\n———————-\n”
puts “\n———————-类Class\n”
Class Vehicle
{
Number no_of_wheels
Number horsepower
Characters type_of_tank
Number Capacity
Function speeding
{
}
Function driving
{
}
Function halting
{
}
}
class Customer
@@no_of_customers=0
def initialize(id, name, addr)
@cust_id=id
@cust_name=name
@cust_addr=addr
end
def hello
@@no_of_customers += 1
puts “Hello Ruby!”,@cust_name,@@no_of_customers
end
end
def hello
@@no_of_customers += 1
puts “Hello Ruby!”,@cust_name,@@no_of_customers
end
cust1=Customer.new(“1”, “John”, “Wisdom Apartments, Ludhiya”)
cust1.hello
cust2=Customer.new(“2”, “Poul”, “New Empire road, Khandala”)
cust2.hello
puts “\n———————-特殊的变量\n”
puts <