Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4616

How does Ruby the String interpolation of a String object?

$
0
0

Is my assumption correct that Ruby does not call the to_s or to_str method when interpreting a String object during string-interpolation?

a = "Hallo"class String  def to_s"Servus"  endenddef a.to_s"Servus"endputs "Hier sagt man #{a}"

=> Hier sagt man Hallo

Is it more efficient to check if an object is a String than to simply call the to_s method?


Viewing all articles
Browse latest Browse all 4616

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>