I recently read a nice post on using StringIO
in Ruby. What the author doesn\'t mention, though, is that StringIO
is just an \"I.\" There\'s no \
Well, a StringBuffer is not quite as necessary in Ruby, mainly because Strings in Ruby are mutable... thus you can build up a string by modifying the existing string instead of constructing new strings with each concat.
As a note, you can also use special string syntax where you can build a string which references other variables within the string, which makes for very readable string construction. Consider:
first = "Mike"
last = "Stone"
name = "#{first} #{last}"
These strings can also contain expressions, not just variables... such as:
str = "The count will be: #{count + 1}"
count = count + 1