ruby 连接字符串

发现如果要把两个字符串连接在一起。如
a = “abc”
b = a + “de”
此时b的值为”abcde”
但如果a = nil时,就会抛出未定义“+”的异常,因为此时a为nil。但如果我们改变一下b右边的表达式,将其改为b = “#{a}de”。这时就不会抛出错误了,此时b=> “de”。

您可能感兴趣的文章

  1. ruby 中 include 与 extend 区别
  2. 为你的类混入Enumerable
  3. ruby initialize 返回对象
  4. puts 返回值
  5. rails3.0怪异的数据库密码配置
  6. ruby 安装 rmagick
  7. rails redirect_to
  8. render partial
  9. belongs_to 选项中的:primary_key
  10. 为gem添加源
分享到Twitter 分享到新浪微博 分享到开心 分享到QQ空间 分享到人人 分享到鲜果 分享到豆瓣 分享到网易微博 分享到搜狐微博
You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.

Powered by WordPress | Find Wireless Deals at BestInCellPhones.com. | Thanks to iCellPhoneDeals.com Free Cell Phones, Find Highest CD Rates and Incinerador De Grasa Revisión