Lean comment blocks

Hat Tip: Vikas Yadav, Online Prototypes 2017

Instead of encountering scores of lines with #comments, instead

puts "x"
  this is a block comment
  You can put anything you like here!

  puts "y"
puts "z"

… is a better way of putting comment blocks

To use comment blocks:

Add a =begin where you want to start commenting out code and an =end where you want it to finish. Make sure you’ve got both parts of the comment block or you will get an error.

All the stuff outside of the comment must work as functional code too. For example

get "/sms/incoming" do 
  session["counter"] ||= 1
  body = params[:Body] || “"

  twiml = Twilio::TwiML::MessagingResponse.new do |r|
    r.message do |m|
      m.body( "You said: " + body + “\n It’s message number #{ session["counter"] }” )
  session["counter"] += 1
  content_type 'text/xml'

This will cause an error because the 2nd end in the statement needs to be inside the comment block for the code to execute correctly. Otherwise the program thinks it’s the end of the route block… then encounters another end a few lines down and is very unhappy.



The latest tutorials sent straight to your inbox.