Upcoming SlideShare
×

# 用Ruby编写博客应用

839 views
756 views

Published on

2010年10月23日shlug聚会上现场演示

Published in: Technology
4 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
839
On SlideShare
0
From Embeds
0
Number of Embeds
23
Actions
Shares
0
12
0
Likes
4
Embeds 0
No embeds

No notes for slide

### 用Ruby编写博客应用

7. 7. 用Ruby编写博客应用 Powered by Rabbit 0.9.0 基本类型 i = 1 # Integer b = true # Boolean f = 1.0/3 # Float n = nil # Null str = "a string" # String sym = :"a string" # Symbol 6/51
8. 8. 用Ruby编写博客应用 Powered by Rabbit 0.9.0 面向对象 i.class # => Integer b.class # => Boolean f.class # => Float n.class # => NilClass str.class # => String sym.class # => Symbol 7/51
9. 9. 用Ruby编写博客应用 Powered by Rabbit 0.9.0 符号 str1 = "a string" str2 = "a string" str1 == str2 # true str1.object_id == str2.object_id # false sym1 = :"a string" sym2 = :"a string" sym1 == sym2 # true sym1.object_id == sym2.object_id # true 8/51
10. 10. 用Ruby编写博客应用 Powered by Rabbit 0.9.0 数组操作 a = [1, 2, 3] a << 4 # a = [1, 2, 3, 4] a[0] # => 1 a[1..3] # => [2, 3, 4] a[1] = "a" # a = [1, "a", 3, 4] a[5] = [1,2] # a = [1, "a", 3, 4, nil, [1,2]] 9/51
11. 11. 用Ruby编写博客应用 Powered by Rabbit 0.9.0 哈希表操作 a = { "a" => 1 } a["a"] # => 1 a["b"] # => nil a["b"] = 2 # a = { "a" => 1, "b" => 2} 10/51
22. 22. 用Ruby编写博客应用 Powered by Rabbit 0.9.0 文件格式 # 文件名: 2010-10-10-a-lucky-day.txt title: "A Lucky Day" date: 10/10/2010 # 今天是我的幸运日 早上在地铁门将要关上的那一刻，我冲进了车厢，于是约会没有迟到... 中午提前了一点去港丽，居然只排了42分钟... 晚上又赶上了末班车... 到家数了数，钱包里面正好有42块钱... 21/51
36. 36. 用Ruby编写博客应用 Powered by Rabbit 0.9.0 Gemﬁle source "http://rubygems.org" gem 'haml' # HAML模版 gem 'rdiscount' # 渲染Markdown gem 'sinatra' # Sinatra gem 'thin' # 应用服务器 gem 'shotgun' # 负责重启服务器 35/51
38. 38. 用Ruby编写博客应用 Powered by Rabbit 0.9.0 Hello, world get '/' do "Hello, world!" end 37/51