ruby code block
程序员文章站
2022-07-14 12:33:14
...
find
find/detect => Object or nil
find_all/select => Array
any? => Boolean
all? => Boolean
delete_if => Array
search
merge后面的会覆盖前面的
h1.merge(h2) {|k, o, n| o < n ? o : n}
>{"a"=>111, "b"=>222, "c"=>444}
(1..5).find {|i| i == 5} >5 (1..10).find {|i| i % 3 == 0} >3 只返回第一个 (1..10).detect {|i| i % 3 == 0} >3 (1..10).detect {|i| (1..10).include?(i * 3)} >1 (1..10).find_all {|i| i % 3 == 0} >[3, 6, 9] (1..10).select {|i| (1..10).include?(i * 3)} >[1, 2, 3] (1..10).any? {|i| i % 3 == 0} >true (1..10).all? {|i| i % 3 == 0} >false [1..10].delete_if {|i| i % 3 == 0} >[1, 2, 4 ,5, 7, 8, 10]
find/detect => Object or nil
find_all/select => Array
any? => Boolean
all? => Boolean
delete_if => Array
search
h1 = { "a" => 111, "b" => 222} h2 = {"b" => 333, "c" => 444} h1.merge(h2) >{“a”=>111, "b"=>333, "c"=>444} h1.merge(h2) >{"a"=>111, "b"=>222, "c"=>444} h1.merge(h2) {|key, old, new| new} >{“a”=>111, "b"=>333, "c"=>444} h1.merge(h2) {|key, old, new| old} >{"a"=>111, "b"=>222, "c"=>444} h1.merge(h2) {|key, old, new| old * 5} >{"a"=>111, "b"=>1110, "c"=>444} h1.merge(h2) do |key, old, new| if old < new old else new end end
merge后面的会覆盖前面的
h1.merge(h2) {|k, o, n| o < n ? o : n}
>{"a"=>111, "b"=>222, "c"=>444}
上一篇: agile rails
下一篇: httpclient
推荐阅读
-
成功解决SyntaxError: Non-UTF-8 code starting with xc0 in file but no encoding declared; see http://p
-
在ASP.NET 2.0中操作数据之七十三:用Managed Code创建存储过程和用户自定义函数(上部分)
-
Ruby元编程基础学习笔记整理
-
详述IntelliJ IDEA提交代码前的 Code Analysis 机制(小结)
-
更改Web Service部署生成的App_Code.dll名称的方法
-
全新Visual Studio Code预览版0.10.10发布下载
-
centos 6下安装innodb_ruby
-
详解VS Code使用之Vue工程配置format代码格式化
-
使用vs code编辑调试php配置的方法
-
使用vue-cli3 创建vue项目并配置VS Code 自动代码格式化 vue语法高亮问题