AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
String interpolation rss builder ruby3/20/2024 ![]() Difference between single or double quotes is that double quotes allow for escape sequences while single quotes do not allow for it. They can also contain control characters. Then, I came to realize in some code that it makes it much readable when I use this syntax for string concatenations as well. C 6.0 introduced a cool feature called String Interpolation, which is an awesome replacement for confusing String.Format syntax, to make them more readable. Two reasons, no need for additional conversions of datatypes to string ruby takes care of it and this process is most of the developers kinda use. C String Interpolation, Performance test. In both the case, in the end, it creates one object but why prefer Interpolation over concatenation. In String Interpolation, it creates an only one object for (“hela “+string+” puri”) and embeds the existing string(weds)to it. Eventually, the objects(1, 2) created in this process gets terminated as their are of no use. Let’s say string=”weds” In string concatenation, if we are concatenating strings like (“hela “+string+” puri”), it creates 3 string objects, it moves from right-to-left, it first creates ” puri” object1, + method sticks the puri with the existing string together and returns weds puri object2 and this again gets stick by + method and forms the final hela weds puri object3. So, the only advantage, We don’t have to convert numbers into a string because ruby takes care of it. ![]()
0 Comments
Read More
Leave a Reply. |