首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > Ruby Rails >

Ruby学习5 知识点总结

2012-09-27 
Ruby学习五 知识点总结+++++++++++++++++++++++++++++++++++++++++++?这句话是什么意思 render:text he

Ruby学习五 知识点总结

+++++++++++++++++++++++++++++++++++++++++++

?

这句话是什么意思 render:text=> "hello world"

?

?

写全了就是
render({:text => "hello world"})

把这个hash作为参数传进去。

?

++++++++++++++++++++++++++++++++++++++++++++

?

Array(nil)??? # => []
Array([])???? # => []
Array(1)???? # => [1]
Array([2])?? # => [2]

?

++++++++++++++++++++++++++++++++++++++++++++

?

各种排序的Ruby实现

http://www.iteye.com/topic/280891

?

+++++++++++++++++++++++++++++++++++++++++++++++++++++++?#find 找出符合条件的第一个元素,返回该元素
#find_all,select 找出符合条件的所有元素,返回结果也是数组
array=[6,1,2,3,4,5]
p array.find{|a| a>2} # 6
p array.find_all{|a| a>2} # [3, 4, 5]
p array.select{|a| a > 2} # [3, 4, 5]?注意代码块:a > 2,相当于 if 的条件。+++++++++++++++++++++++++++++++++++++++++++++++++++++++

?

"q"或者"Q"后面跟着的是分隔符,如果它是开大括号、方括号、圆括号或者是小于号,那么字符串结束于和它匹配的符号处,否则,结束于和它相同的字符处

?

http://www.zzbaike.com/wiki/Ruby-%E6%A0%87%E5%87%86%E7%B1%BB%E5%9E%8B

?

++++++++++++++++++++++++++++++++++++++++++++

?

方法可以通过 if 语句加上 block_given? 条件,来判断方法在执行的时候,是否有块在后面,如果有,就执行if语句,再根据yield调用块,如果后面没有块,就继续执行if后面的代码?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?? str.upcase 等同 str.send("upcase")
???send 发送的消息,在程序运行时是可变的,可以根据不同的输入,动态的向对象发送不同的消息

?

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

Gemfile.lock 则用来记录本机目前所有依赖的 RubyGems 和其版本?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

a?=?[?1,?3,?5,?7,?9?]??
a[1,?3]??????????>>??????[3,?5,?7]??
a[3,?1]??????????>>??????[7]??
a[-3,?2]?????????>>??????[5,?7]??



(译者注:注意负整数索引的方向依然是从前向后)

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

?

++++++++++++++++++++++++++++++++++++++++++++

?

?

++++++++++++++++++++++++++++++++++++++++++++

热点排行