Showing posts with label command line. Show all posts
Showing posts with label command line. Show all posts

Monday, February 22, 2016

Simple IRB formatting trick

If you execute IRB with the command line flag –noprompt you will enter in to an IRB session with none of the extra characters showing up on the left side of the terminal. This is great if you want to experiment with code and then use the mouse to copy & paste from it. Like, for example, in a code blog like the one you’re reading…

(Thanks to 6ftdan for this cool tip.)

Monday, January 11, 2016

No return value in rails console

A quick tip when working in rails console. If you're testing commands to run and don't want the console to output the return value, just append a semicolon to your ruby code.

  User.all
  # => [#<user:0x007fd72a408630> {:id => 1, :name => "Mr. T", ...}, tons and tons of other records]
  User.all;
  # => nothing!

OK, so that's a contrived example, but this really comes in handy

  • when creating records, or 
  • if you need to update several records in one shot and don't want to see the return values, or
  • POSTing to an external API and avoiding all the cruft that comes in the response