开发者

What does "" (two double quotes) do in Ruby?

开发者 https://www.devze.com 2023-01-14 18:42 出处:网络
I\'ve seen Ruby code in which there are only two doub开发者_如何学Gole quotes (\"\") on a line. What does that line do?I assume you might have seen a code like this.

I've seen Ruby code in which there are only two doub开发者_如何学Gole quotes ("") on a line. What does that line do?


I assume you might have seen a code like this.

def some_method
   #do some operations
   ""
end

In this context, it means that the method is returning an empty string. In Ruby, the last evaluated operation in a method is what is returned from that method. So in this case, it returns an empty string literal.


Two double quotes represent an literal empty string in Ruby. And in many other languages.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号