Using Methods To Make Templates More Powerful

Dave Kimura
Dave Kimura
Thor is a powerful utility and it drives the Rails Application Templates. Sometimes, we may want to have some text that is beyond the normal Terminal color. If you've ever ran a script in your terminal, you've probably noticed some kind of coloring scheme on certain text. We can do that too, but make it in a repeatable fashion.

def print_green(heredoc)
  puts set_color heredoc, :green
end

print_green <<~DOC
Some multiline
text goes here
DOC

Here, we create a method called print_green and when we call the function, we're passing in a HEREDOC which will allow multiline text to be passed in.