---
title: 'This week in #dev (Pilot)'
teaser: 'Highlights of what happened in our #dev channel on Slack this week.

  '
tags: this week in dev,rails,ruby,javascript,til,tip
author: thoughtbot
published_on: 2022-12-13
---

## This week in our Slack channels

We usually avoid private messages. Among [other benefits], it helps us to share
knowledge across the company. Many interesting conversations and discoveries
happen on public channels like `#dev` or `#design`. These are some of the most
valuable resources we have, and now we decided to share some highlights with
you, dear reader!

Here's a selection of the most interesting conversations that happened in our
`#dev` channel this week:

[other benefits]: https://thoughtbot.com/blog/private-messages-not-inclusive

## Highlights

### Ruby's Kernel.abort

[Matheus] shares that he has often created a method like this for scripts:

```rb
def exit_with_error(msg)
  $stdout.write(msg)
  exit(-1)
end
```

Recently, he discovered Ruby's `Kernel.abort` which [essentially does this out
of the box](https://rubyapi.org/3.1/o/kernel#method-i-abort).

### Rolling back Rails migrations

Elisa Verna shares how using `rails db:rollback STEP=number` is much more
convenient than running migrations down individually by version number. [Steve
Polito] also mentions `rails db:migrate:redo`, which is a shortcut for doing a rollback
and then migrating back up again (and also accepts the `STEP` parameter).

```sh
# Rollsback and up again 3 migrations
bin/rails rails db:migrate:redo STEP=3
```

<aside class="info">
  <h4>Reversible migrations</h4>
  <p>
    As noted by <a href="https://twitter.com/neilvilela">Neil</a>,
    <code>rails db:migrate:redo</code> is a good way to ensure your migrations are reversible.
  </p>
  <p>
    We have a
    <a href="https://github.com/thoughtbot/dotfiles/blob/main/aliases#L12">
      handy alias
    </a> on our dotfiles repo to help you to check that!
  </p>
</aside>

### Formatting lists in JavaScript

Did you know that JS has [its own version] of the famous Rails convenience [`to_sentence`]?

```js
const vehicles = ['Motorcycle', 'Bus', 'Car'];

const formatter = new Intl.ListFormat('en', {style: 'long', type: 'conjunction'});

console.log(formatter.format(vehicles));
// expected output: "Motorcycle, Bus, and Car"
```

It's worth checking the [other constructors available], like [`Intl.NumberFormat`].

[its own version]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat
[`to_sentence`]: https://api.rubyonrails.org/classes/Array.html#method-i-to_sentence
[other constructors available]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#constructor_properties
[`intl.numberformat`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat

### Formatting Java code

In case you're working with Java, [Mike Burns] shares [a quick guide] on how to
format a selection of code (or the whole file) using IntelliJ.

[a quick guide]: https://www.jetbrains.com/idea/guide/tips/reformat-file/

## Thanks

This edition was brought to you by Elisa Verna, [Matheus Richard][matheus],
[Mike Burns], [Neil Vilela][neil] and [Steve Polito]. Thanks to all
contributors!

[matheus]: https://thoughtbot.com/blog/authors/matheus-richard
[mike burns]: https://thoughtbot.com/blog/authors/mike-burns
[neil]: https://twitter.com/neilvilela
[steve polito]: https://thoughtbot.com/blog/authors/steve-polito
