- 浏览: 2075656 次
- 性别:
- 来自: NYC
文章分类
- 全部博客 (628)
- Linux (53)
- RubyOnRails (294)
- HTML (8)
- 手册指南 (5)
- Mysql (14)
- PHP (3)
- Rails 汇总 (13)
- 读书 (22)
- plugin 插件介绍与应用 (12)
- Flex (2)
- Ruby技巧 (7)
- Gem包介绍 (1)
- javascript Jquery ext prototype (21)
- IT生活 (6)
- 小工具 (4)
- PHP 部署 drupal (1)
- javascript Jquery sort plugin 插件 (2)
- iphone siri ios (1)
- Ruby On Rails (106)
- 编程概念 (1)
- Unit Test (4)
- Ruby 1.9 (24)
- rake (1)
- Postgresql (6)
- ruby (5)
- respond_to? (1)
- method_missing (1)
- git (8)
- Rspec (1)
- ios (1)
- jquery (1)
- Sinatra (1)
最新评论
-
dadadada2x:
user模型里加上 protected def email ...
流行的权限管理 gem devise的定制 -
Sev7en_jun:
shrekting 写道var pattern = /^(0| ...
强悍的ip格式 正则表达式验证 -
jiasanshou:
好文章!!!
RPM包rpmbuild SPEC文件深度说明 -
寻得乐中乐:
link_to其实就是个a标签,使用css控制,添加一个参数: ...
Rails在link_to中加参数 -
aiafei0001:
完全看不懂,不知所然.能表达清楚一点?
"$ is not defined" 的问题怎么办
Someone recently emailed the ruby-core mailing list asking "Is there some list of 'bullet points' on the major differences between the syntax of Ruby 1.8 and Ruby 1.9 available somewhere?" The response, of course was a link to the definitive list of changes in Ruby 1.9.
But that is an exhaustive list instead of just highlighting the major changes. So, the following is my somewhat more digested list of the important changes, as I understand them. Additions, corrections, clarifications, and so forth are welcome in the comments.
Text
- Characters are represented by single-character strings, rather than integers:
?A
returns"A"
instead of 65- "HELLO"[1] returns "E" instead of 69.
s[x]
is now the same ass[x,1]
- Use
ord
method of String to get character encoding. It returns the encoding of the first character of the string
- Strings are no longer
Enumerable
, and theeach
method has been removed. Useeach_line
andeach_byte
to iterate lines and bytes. Both of these methods can return enumerators (see below), which areEnumerable
. - Ruby 1.9 adopts the Oniguruma regexp engine, which adds advanced new features for regular expression wizards.
- Additional changes are expected to Ruby's Unicode and multi-byte string support, but Matz has not unveiled them yet. Strings may have an
encoding
method for querying or setting their encoding.
Ranges
member?
andinclude?
work differently if the endpoints of a range are not numbers: they actually iterate withsucc
to test membership in that case.- The new method
covers?
does whatmember?
andinclude?
did in 1.8
Hashes
- New hash syntax. When the keys of a hash are symbols, you can move the colon from the beginning of the symbol to the end (no space allowed) and omit the
=>
. So this hash{:a=>1,:b=>2}
turns into{a:1,b:2}
. The Ruby 1.8 syntax is still supported, of course.
Parallel Assignment
- Any number of splat operators may appear on the right-hand side of a parallel assignment in Ruby 1.9. Previously only the last rvalue could have a splat.
- The left-hand side of a parallel assignment may have only one splat operator, as always, but it is no longer required to be on the last lvalue. In Ruby 1.9 a splat may appear before any one lvalue.
- Remember that the rules of parallel assignment apply to block invocation as well: the arguments to
yield
are rvalues, and the block parameters are lvalues. So these splat changes apply to blocks as well. - In Ruby 1.8, the value of a parallel assignment expression was an array of the lvalues. For efficiency, Ruby 1.9 evaluates all parallel assignments to
true
.
Enumerators
- The iterator methods of core classes and modules like
String
,Fixnum
,Array
,Hash
andEnumerable
now return an enumerator object when invoked with no block. An enumerator is anEnumerable
object. The enumerator return by each of these iterator methods uses that underlying iterator in place of theeach
method normally used by theEnumerable
mixin. So we can write things like:counter = (1..10).each # returns an enumerator counter.each_with_index { |n,i| puts n,i }
- Ruby makes
Enumerable::Enumerator
core, so you no longer have to require "enumerator" to get methods likeenum_for
Blocks
- Block parameters are always local to their blocks, even when the enclosing scope includes a variable by the same name. Use -w to get a warning when this will change the behavior of your code.
- Block parameters must be local variables in Ruby 1.9. No more assigning to instance variables or global variables as a side-effect of block invocation
- You can declare block-local variables in Ruby 1.9. Just follow the ordinary list of block parameters with a semi-colon and follow it with a comma-separated list of variable names:
With this block declaration,hash.each { |k,v; x,y,z| ... }
x
,y
, andz
will be local to the block, even if they are already defined in the enclosing scope. - As per the parallel-assignment changes described above a block parameter list may a splat operator before any one parameter. It is no longer required to be the last one.
- The last block parameter may be prefixed with an ampersand to make it receive a block, just as you can do with methods. This is typically only useful when the block is being turned into a proc or lambda
Procs and Lambdas
Kernel.proc
is now a synonym forProc.new
:proc
now creates a proc andlambda
creates a lambda. (Both procs and lambdas are still instances ofProc
, of course.)- The
Symbol.to_proc
method is now built-in to Ruby. - Ruby 1.9 supports a (strange at first) new syntax for defining lambdas:
->(x,y) { x + y } # same as lambda {|x,y| x + y}
- Parentheses are optional in this new syntax:
->x,y { x + y } # same as lambda {|x,y| x + y}
- The new lambda syntax supports block-local variable declarations following a semicolon just as the regular block syntax does.
- The new lambda syntax allows argument defaults using the same syntax as method declarations:
sale_price = ->(price,discount=.25) { (1.0-discount)*price }
- Parentheses are optional in this new syntax:
- Procs and lambdas can be invoked with parentheses preceded by a period. Given a lambda
sum
, the following three lines are synonyms:sum.call(1,2) sum[1,2] sum.(1,2)
- Procs now have a
yield
method that is an alternative tocall
.yield
uses yield semantics rather than method calling semantics to invoke the proc. This means that it is more relaxed about arity mis-matches and behaves like parallel assignment when the argument is a single array.
Bindings
Binding
objects have aneval
method to evaluate in that binding. This is an alternative to passing the binding as the second argument toKernel.eval
.Proc.binding
is now a private method. It is not clear if this is a bug or if that method will no longer be available.
Continuations
Continuations are not supported in Ruby 1.9
Private Methods
- The method name resolution algorithm has changed or may be changing to alter the way private methods are looked up. The details are still unclear (to me, at least).
Class Variables
- Class variables are no longer shared by a class and its subclasses. A subclass can read the values of class variables defined by its superclass. But if it sets the value of such a variable, it simply creates its own local copy of the variable, and no longer alters the value seen by the superclass.
Math
Math.log2
computes base-2 log- Math.log(x,y) computes the log base-y of x
———————————————————————野蛮小分割————————————————————————————
发表评论
-
eloquent ruby 读书笔记
2012-02-22 07:24 1463节省时间就草记,只记录新鲜,容易忘的 1. case 的判 ... -
Rails 3 in action 读书笔记
2012-02-11 23:54 1364那天看到IE有战友贴了这个书,就想找个时间读读,有收获随笔记下 ... -
The Rails3 Way, Second Edition
2011-04-25 10:23 1692顺便链接一个agile web development wi ... -
the rspec book 下载
2010-09-20 18:17 4337这是写rspec 和 cucumber 一直翻的书,当前最 ... -
电子书推荐 Textmate使用的书
2010-09-07 10:00 1568引用TextMate is a powerful too ... -
ruby电子书资源
2010-08-14 11:49 1756引用 Though we don't like to adm ... -
关于ruby 重构的电子书 资料两本
2010-08-09 20:10 1808Refactoring Ruby Edition 电子书 ... -
pro git 中文版下载
2010-07-06 10:17 11913感觉所有git的问题可以 ... -
peeping into memcached
2009-04-21 23:52 0http://blog.evanweaver.com/arti ... -
Agile Web Development with Rails 3rd 正式版
2009-04-08 13:33 3401Agile Web Development with Rail ... -
在Rails下连接SQL Server 2005 分页
2009-04-03 01:57 2406For a Rails/SQLServer applicati ... -
REST与Web services
2009-04-01 14:33 3098问题:你如何看待一个房间中两个或多个架构师?回答:是争论。既然 ... -
使用cucumber测试过程中de-bug
2009-04-01 01:51 1477最近,Rails工程中,做测试和集成测试的时候,Cucumbe ... -
关于Rails 2.3 十件你应该知道的事
2009-04-01 01:20 1843首先,这个是一篇粉饰Rails2.3的文章,挑选了十个方面展示 ... -
在Rails 2.3 中测试cookie
2009-03-31 18:48 2008Testing Cookies in Rails 2.3 近 ... -
使用Rspec的好处
2009-03-31 18:44 1965本文将从下面几个方面,来阐述使用Rspec的好处 * ... -
5个使用Rails控制台的有用技巧
2009-03-31 18:36 4824update: 2011/10/26 1. 只想测试不想,真 ... -
The Ruby Programming Language 介绍
2009-03-29 11:35 1640点击这里下载chm part1 ... -
一些个人的在线资料
2009-03-28 11:56 1116MoutainWest Conference 视频的 ... -
从scope说起
2009-03-27 00:42 1257预计将从scope说起 以便理解Rails 2.3支持的d ...
相关推荐
Ruby 1.8和1.9是Ruby语言的两个重要版本,它们在许多方面有所不同,同时也对Ruby的发展产生了深远的影响。 Ruby 1.8是Ruby的一个早期版本,发布于2004年,它引入了许多特性,如块语法的改进、元编程能力的增强以及...
《Ruby程序设计语言》是Ruby的权威指南,全面涵盖该语言的1.8版和1.9版。本书详尽但并不拘泥于语言规范,既适合首次接触Ruby的资深程序员,同样也适合那些想要挑战对这门语言的理解并更深入掌握它的Ruby程序员。本书...
此 Ruby SDK 适用于 Ruby 1.8.x, 1.9.x, jruby, rbx, ree 版本,基于 七牛云存储官方API 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个...
本书详细介绍了Ruby 1.8和1.9版本各方面的内容。在对Ruby进行了简要的综述之后,本书详细介绍了以下内容:Ruby的句法和语法结构,数据结构和对象,表达式和操作符,语句和控制结构,方法、proc、lambda和闭包,反射...
Ruby 1.9 的发布对Ruby社区带来了显著的变化,尤其是其与之前的1.8版本之间的不兼容性。这种不兼容性源于对Ruby语言及其核心库的深入修改,目的是提升语言性能和规范。Ruby 1.9.0的推出并非完全稳定,Matz,即Ruby的...
ruby 1.8 特性 1.6.8到1.8.0的变更点(总结) ruby 1.9 特性 obsolete 对应DOSISH 附录 疑似BNF的Ruby语法 Ruby术语集 Ruby的运行平台 pack模板字符串 sprintf格式 Marshal格式 Ruby FAQ Ruby的陷阱 ...
支持旧版本:Rails 2/3/4,Ruby 1.9 +,REE,带有RubyBench补丁的Ruby 1.8。 建立 滑轨5 在Rails 5(以及Rails 3和4)上,将其添加到config/application.rb的顶部: require 'trashed/railtie' 并在您的应用程序...
此外,本书涉及了Ruby不同版本(包括Ruby 2.x、1.9和1.8)的内部实现。作者并没有停留在表面的代码编写上,而是深入到了Ruby的不同版本中,揭示了随着语言版本迭代,内部实现上的变化和改进。 书中还提到了Ruby中...
12. **ruby1.8 1.9问题**:Ruby 1.8和1.9是两个不同的版本,每个版本有自己的特点和不兼容性。这里可能讨论了在升级或迁移过程中遇到的问题以及解决策略。 以上是基于提供的文件标签和部分内容所推测的Ruby和Rails...
《Ruby编程语言》详细介绍了Ruby1.8和1.9版本各方面的内容。在对Ruby进行了简要的综述之后,《Ruby编程语言》详细介绍了以下内容:Ruby的句法和语法结构,数据结构和对象,表达式和操作符,语句和控制结构,方法、...
80% of the material will also be useful for legacy Ruby 1.8 users, and there is 1.8-specific advice as well. Table of Contents Chapter 1. What Makes Ruby Code Fast Chapter 2. Fix Common Performance ...
书中对Ruby 2.x、1.9和1.8版本都有所覆盖,让读者可以了解到Ruby发展的不同阶段。 另一个值得探讨的部分是Ruby的垃圾回收算法。Ruby的垃圾回收机制是自动内存管理的核心,它负责回收不再使用的对象所占用的内存空间...
midilib与Ruby 1.8.x 1.9.x和2.x兼容。 依赖关系 midilib不需要任何其他软件包。 tests目录中的测试套件需要测试框架TestUnit,该框架随Ruby 1.8及更高版本一起提供,也可以在Ruby Application Archive( )中找到...
注意:请使用Ruby 1.8.x(1.9中的语法突出显示有些问题) 第一次运行 安装宝石 sudo gem install jekyll -V --no-ri --no-rdoc sudo gem install rdiscount -V --no-ri --no-rdoc 可选依赖项: (不与Ruby 1.9...
6. `ruby-oci8-1.0.7-x86-mswin32-60.gem`:专为Windows上的Ruby 1.9.x编译的版本。 7. `ruby-oci8-2.1.0.tar.gz` 和 `ruby-oci8-2.0.6.tar.gz`:源代码包,可以自行编译安装。 8. `ruby-oci8-1.0.7.tar.gz`:同上,...
改编自 TextMate 使用的方法,该库提供了一个命令ruby-hash-syntax-toggle ,它尝试在 1.8 和 1.9 哈希样式之间自动转换选定的 ruby 代码区域。 安装 如果您选择不使用方便的包之一,则需要将包含ruby-hash-...
1.9版本相对于之前的1.8.x系列是一个重大升级,它对语言的许多方面进行了优化。其中最显著的变化之一是默认编码改为UTF-8,这使得处理多语言文本变得更加方便。此外,1.9版本还引入了新的语法特性,如块的语法更简洁...