Today I Learned

Giant Monkeys Learning

Copy-paste friendly executable comments in Ruby

Imagine this comment on top of a ruby file:

### usage:
#### reset and seed database
# rake db:reset 
#### get korona base data
# rails runner 'Korona.synchronize_all!'
#### create valid day tickets in local development
# rails runner rails-runner/create_valid_ticket_for_shop_tests.rb

It is supposed to document the usage and gives executable example lines. However to use them verbatim you have to copy-paste them line by line, removing the leading #.

There is a better alternative using the mostly frowned upon=begin / =end comment style:

=begin usage:
rake db:reset                                                   # reset and seed database
rails runner 'Korona.synchronize_all!'                          # get korona base data
rails runner rails-runner/create_valid_ticket_for_shop_tests.rb # create valid day tickets in local development
=end

Now it is possible to copy-paste the whole block into a shell to execute.