读书人

ruby 的 Enumerable 步骤

发布时间: 2012-09-14 23:00:49 作者: rapoo

ruby 的 Enumerable 方法
grep
是===来判断是否存在符合条件的sub enumerable

c = IO.constantsc.grep(/SEEK/)         #=> [:SEEK_SET, :SEEK_CUR, :SEEK_END]res = c.grep(/SEEK/) {|v| IO.const_get(v) }res                    #=> [0, 1, 2]


用来差方法很不错
array.public_methods.grep(/^each_(.*)$/){ puts $1}#index#with_index#entry#slice#cons#with_object
1 楼 fireDragonpzy 2012-02-23 Array.instance_methods

读书人网 >Ruby Rails

热点推荐