Ruby学习笔记

Posted bob

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ruby学习笔记相关的知识,希望对你有一定的参考价值。

#!/usr/bin/ruby

puts "Hello, Ruby, what is your name?"
$name = STDIN.gets
puts "Hi, I am "+$name

def welcome(name,a = 9,b = 9,*c)
    puts "Hi #{name}"
    c.each{|x| print "#{x}"}
#    print "a = "+ $a
    a = 10; b = 11
#    print "Hi, b" + $b
    res = a * b
end

#welcome("RUBY")
puts welcome "ruby",3,6,7,8

x = 100000000000000000000
puts "#{x}  " + x.class.to_s

puts "Hello".upcase()

s = "shit"; f = "fuck"
s,f = f,s
arr = [1, 2, s, f]
puts arr[2]
puts arr[-1]
puts arr.inspect

#Hash Table
cars = {
    altima => Nissan,
    camry => Toyota,
    rx7 => Mazda
}
cars[v] = Volkswagon
puts cars[rx7]
p cars[v]
#puts *.inspect 缩写
p cars

#each 迭代
toppings = Hash["pancakes","syrup","Pizza","Pepper","Cereal","Sugar"]  
toppings.each{|name, price| puts "#{name} points to #{price}"}
myToppings = toppings.select{|name, price| price > "Pepper"}
p myToppings.inspect

#using of ..[] and ...[)
(a..g).each{ |letter| print letter }
puts
(a...g).each{ |letter| print letter }
puts

  另存为*.rb文件,在终端执行ruby *.rb。

以上是关于Ruby学习笔记的主要内容,如果未能解决你的问题,请参考以下文章

ruby 我感兴趣的库中的代码片段

Ruby 学习笔记2

[原创]java WEB学习笔记61:Struts2学习之路--通用标签 property,uri,param,set,push,if-else,itertor,sort,date,a标签等(代码片段

Ruby 学习笔记1

ruby 学习笔记一

ruby学习笔记