- 浏览: 2683778 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
80后的童年2:
深入浅出MongoDB应用实战开发网盘地址:https://p ...
MongoDB入门教程 -
shliujing:
楼主在不是精通java和php的前提下,请不要妄下结论。
PHP、CakePHP哪凉快哪呆着去 -
安静听歌:
希望可以一给一点点注释
MySQL存储过程之代码块、条件控制、迭代 -
qq287767957:
PHP是全宇宙最强的语言!
PHP、CakePHP哪凉快哪呆着去 -
rryymmoK:
深入浅出MongoDB应用实战开发百度网盘下载:链接:http ...
MongoDB入门教程
本文节选自ORUG的Tyler Hunt的《Advanced Ruby》
Syntax Sugar
Alternative Syntax
Variables
Blocks & Closures
Exceptions
Classes
Modules
Syntax Sugar
if not version.empty? return version.gsub('_', '.') end unless version.empty? return version.gsub('_', '.') end
return if version.valid? return if not version.valid? return unless version.valid?
if person.xy? gender = 'M' else gender = 'F' end gender = person.xy? ? 'M' : 'F'
for item in items puts item.to_s end items.each do |item| puts item.to_s end
for i in 1..3 quantity = gets.chomp.to_i next if quantity.zero? redo if quantity > LIMIT retry if quantity == RESTART break if quantity == FINISHED quantities[i] = quantity end
(1..5).collect { |i| i * i } # [1, 4, 9, 16, 25] (1..5).detect { |i| i % 2 == 0 } # 2 (1..5).select { |i| i % 2 == 0 } # [2, 4] (1..5).reject { |i| i % 2 == 0 } # [1, 3, 5] (1..5).inject { |sum, n| sum + n } # 15
Alternative Syntax
puts '"Hello World!"\n' # "Hello World!"\n puts "\"Hello World!\"\n" # "Hello World!" puts %q("Hello World!"\n) # "Hello World!"\n puts %Q("Hello World!"\n) # "Hello World!" puts %!"Hello World\!"\n! # "Hello World!"
exec('ls *.rb') system('ls *.rb') `ls *.rb` %x(ls *.rb) system('echo *') system('echo', '*')
/[ \t]+$/i %r([ \t]+$)i Regexp.new( "[ \t]+$", Regexp::IGNORECASE )
["one", "two", "three"] %w(one two three)
1..5 Range.new(1, 5) # (1..5).to_a == [1, 2, 3, 4, 5] 1...5 Range.new(1, 5, true) # (1...5).to_a == [1, 2, 3, 4]
Variables
$global_variable @instance_variable @@class_variable CONSTANT local_variable
Blocks & Closures
with_block a, b { ... } # with_block(a, b { ... }) with_block a, b do ... end # with_block(a, b) { ... }
puts begin t = Time.new t.to_s end
def capitalizer(value) yield value.capitalize end capitalizer('ruby') do |language| puts language end
def capitalizer(value) value = value.capitalize if block_given? yield value else value end end
def capitalizer(value) yield value.capitalize end def capitalizer(value, &block) yield value.capitalize end
proc_adder = Proc.new { return i + i } lambda_adder = lambda { return i + i }
visits = 0 visit = lambda { |i| visits += i } visit.call 3
Exceptions
begin # code rescue AnError # handle exception rescue AnotherError # handle exception else # only if there were no exceptions ensure # always, regardless of exceptions end
def connect @handle = Connection.new rescue raise ConnectionError end
Classes
class Person attr_accessor :name def initialize(first, last) name = first + ' ' + last end end person = Person.new('Alex', 'Chin')
class Person attr_accessor :name class Address attr_accessor :address, :zip end end address = Person::Address.new
class Person attr_accessor :name end class Student < Person attr_accessor :gpa end student = Student.new student.name = 'Alex Chin'
Modules
module Demographics attr_accessor :dob def age (Date.today - dob).to_i / 365 end end class Person include Demographics end
person = Person.new person.extend Demographics
module Demographics def self.included(base) base.extend ClassMethods end module ClassMethods def years_since(date) (Date.today - date).to_i / 365 end end end
发表评论
-
用了TextMate才知道什么叫神级Editor
2011-03-09 04:51 58002一直用Eclipse作为开发Ruby和Java项目的IDE,但 ... -
Ruby使用OAuth登录新浪微博和豆瓣
2011-01-09 12:49 4470首先需要安装oauth这个gem包 gem install ... -
使用Passenger+nginx部署Rails
2010-12-28 15:12 50351. Install Passender gem instal ... -
markItUp+rdiscount搭建Rails下可视化Markdown编辑器
2010-12-21 17:48 5476markItUp是基于jQuery的可视化编辑器,支持Html ... -
Rails3 and MongoDB Quick Guide
2010-12-10 14:13 2761Install MongoDB Download: http: ... -
基于ruby-protobuf的rpc示例
2009-08-11 11:51 41531, 安装ruby-protobuf gem instal ... -
Ruby导出xls和csv的utf-8问题的解决
2009-02-04 15:05 6864数据库数据为utf-8格式,包括中文和拉丁文等等 导出文件xl ... -
URL/HTML/JavaScript的encode/escape
2009-01-04 13:03 9349最近经常被URL、HTML、JavaScript的encode ... -
各种排序的Ruby实现
2008-11-27 14:51 4009Θ(n^2) 1, Bubble sort def bu ... -
12月5日北京RoR活动!
2008-11-26 18:38 3025又是一年过去了,Rails在国内的发展势态良好,很多使用RoR ... -
Rails程序开发的最大问题是代码规范
2008-08-28 11:56 5591使用Rails开发大型复杂B2B应用一年了,这个项目目前开发人 ... -
Web开发大全:ROR版——推荐序
2008-07-09 00:39 2432来自http://www.beyondrails.com/bl ... -
深入ActionMailer,使用Sendmail发邮件
2008-07-03 11:41 3401来自: http://www.beyondrails.com/ ... -
Rails里如何结合ExceptionNotification配置gmail账户发邮件
2008-06-19 19:56 31071,安装ExceptionNotification rub ... -
使用coderay和railscasts样式进行代码高亮
2008-06-17 00:16 2401CodeRay是一个语法高亮的Ruby库,效率很不错。 Cod ... -
Capistrano试用
2008-06-16 19:05 19641,客户端机器安装Capistrano gem insta ... -
lighttpd真垃圾啊
2008-06-04 18:38 2550使用lighttpd+fcgi跑Rails程序,文件上传会si ... -
将gem变成plugin
2008-06-04 11:27 1810有什么样的需求就有什么样的对策 当vhost上的帐号没有ge ... -
在Rails里使用ReCaptcha添加验证码
2008-06-03 15:51 42751,去http://recaptcha.net/sign up ... -
Rails里给文件上传添加progress_bar
2008-05-27 17:00 2100文件上传很慢时,UI没有什么用户提示,这样让人很费解,所以我们 ...
相关推荐
You'll enter at Ruby's language basics and work through progressively advanced Ruby features such as classes, inheritance, and blocks. As your Ruby skills grow, you'll tackle deep topics such as ...
Chapter 11: Advanced Ruby Features Chapter 12: Tying It Together: Developing a Larger Ruby Application Part 3: Ruby Online Chapter 13: Two Web Application Approaches: Rails and Sinatra Chapter 14: ...
In Part II, you'll take your skills to the next level as you build a social networking app with more advanced Ruby tools, such as modules and metaprogramming, and advanced data modeling techniques ...
- **Advanced Rails**:针对高级Ruby on Rails开发者的深入指南。 - **Rails Cookbook**:涵盖Ruby on Rails框架中的各种常见问题解决方案。 - **Ruby Pocket Reference**:提供Ruby语言核心特性的快速参考手册。 - ...
1. **加密算法支持**:Lockbox支持多种加密算法,如AES(Advanced Encryption Standard),RSA,ECB(Electronic Codebook),CBC(Cipher Block Chaining)等。AES是目前最常用的对称加密算法,而RSA则是一种非对称...
RabbitMQ是一种流行的开源消息代理,它实现了Advanced Message Queuing Protocol (AMQP)标准。它允许应用程序之间通过创建、发送、接收和存储消息来通信,这种解耦的方式使得系统更加健壮和灵活。 Sneakers的核心...
Dig under the surface and explore Ruby's most advanced feature: a collection of techniques and tricks known as metaprogramming. In this book, you'll learn metaprogramming as an essential component of ...
1. **消息传递**:书中可能详细讲解了如何使用Ruby来构建消息传递系统,如通过AMQP(Advanced Message Queuing Protocol)或者RabbitMQ等中间件实现异步通信。消息队列在系统解耦和提高可扩展性方面扮演着重要角色。...
O'Reilly旗下的资源还包括了《Ruby Cookbook》、《Learning Ruby》、《Advanced Rails》、《Rails Cookbook》和《Ruby on Rails: Up and Running》等,这些资源对于想要在Ruby领域深入学习的开发者来说,都是宝贵的...
5. 其他资源:文档提到了O'Reilly提供的其他相关资源,包括《Ruby Cookbook》、《Learning Ruby》、《Advanced Rails》、《Rails Cookbook》和《Ruby Pocket Reference》等。这些资源涵盖了从基础到高级的Ruby编程...
"Ruby-服务器优化的Ruby发行版通过APTYUM实现更少内存更快速易于安装和安全补丁"这个主题就聚焦于这样的发行版,特别是如何通过APT(Advanced Package Tool)和YUM(Yellowdog Updater, Modified)这两个包管理器来...
"Advanced Rails" 涵盖了Rails开发中的高级主题和技术,是Ruby on Rails学习进阶的重要资源,尤其适合已经对基础Rails有一定了解的开发者。 在Web开发领域,Rails以其高效、简洁的代码和“约定优于配置”的哲学吸引...
- **Advanced Rails**:专注于Ruby on Rails框架的高级用法和技术细节。 - **Rails Cookbook**:类似于Ruby Cookbook,但专门针对Rails框架。 - **Ruby Pocket Reference**:一本便携式的参考手册,涵盖了Ruby语言的...
Eric is a full featured Python and Ruby editor and IDE, written in python. It is based on the cross platform Qt gui toolkit, integrating the highly flexible Scintilla editor control. It is designed to...
### Ruby Pocket Reference Key Points **Title and Description Overview:** The "Ruby Pocket Reference" by Michael Fitzgerald is a concise and practical guide designed to serve as a quick reference for...
Beginners and advanced Rubyists alike will learn how to program with: <br> <br>Strings and numbers <br>Arrays and hashes <br>Classes, modules, and namespaces <br>Reflection and ...