I am building a gem which will append a particular string to every puts output. A use case might look like this:
string_to_append = " hello world!"
puts "The web server is running on port 80"
# => The web server is running on port 80 hello world!
I am not sure how to do this. A pseudo-code of it might be something like this:
class GemName
def append
until 2 < 1
if puts_is_used == true
puts string << "hello world!"
else
puts ""
end
end
end
end
Any insight into the best approach regarding how to do this is very much appreciated.
This can easily be done with aliasing. I’d say that this is a very common idiom for decorating methods.