Switch in Scala (pattern matching)

Scala has a powerful pattern matching mechanism, that we can think of a kind of “switch” if we come from another programming language, but it’s much more powerful and I’d love to explore some of its options here. A simple switch in Scala would look like this:

a match {
  case 1 => "One"
  case 2 => "Two"
  case _ => "Whatever"

SBT in Scala compile when you save a file

I’ve worked on some Scala projects recently using SBT (Scala Building Tool) and every time I had a change in a file I needed to go to SBT and type compile until I found a simple instruction to keep it compiling for me. Just execute SBT and run the following command: ~ compile Now every time you save a file it will be compiled automatically. In the official documentation you can see more details.

Set Content Type in RSpec

The last week I had a spec with a request where I needed to specify the content type and Google sensei didn’t help me.

It took me an hour until I finally found it, so let me show here briefly how to do it just in case I have to find it again.