ruby 问题总结

1.routes collection 和member的区别

例:
resources :photos do member do get :preview endend
resources :photos do collection do get :preview endend
结果
member /photos/1/preview preview_photo_path(photo)Acts on a specific resource so required id (preview specific photo)
collection /photos/preview preview_photos_url Acts on collection of resources(display all photos)
2.require 和 load的区别
require 只加载一次,load加载多次,load每次加载到该文件的时候执行改文件,require只在第一次执行是载入,以后碰到时自动忽略。require如果为ruby代码,可以省略后缀 。require将所有加载的文件保存在$变量中。
require ,load用于包含文件,include则用于包含的模块。
require一般用于加载库文件,load一般用于加载配置文件
3.join和spilt
join array to string
arr = ["hello", "world", 123]
puts arr.join(", ")
puts arr.join
hello, world, 123
helloworld123
spilt string to array
" now's  the time".split        #=> ["now's", "the", "time"]
" now's  the time".split('')   #=> ["now's", "the", "time"]
" now's  the time".split(//)   #=> ["", "now's", "", "the", "time"]
"1, 2.34,56, 7".split(%r{,\s*}) #=> ["1", "2.34", "56", "7"]
"hello".split(//)               #=> ["h", "e", "l", "l", "o"]
"hello".split(//, 3)            #=> ["h", "e", "llo"]
"hi mom".split(%r{\s*})         #=> ["h", "i", "m", "o", "m"]

"mellow yellow".split("ello")   #=> ["m", "w y", "w"]
"1,2,,3,4,,".split(',')         #=> ["1", "2", "", "3", "4"]
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值