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

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

Welcome to another edition of This Week in #dev, a series of posts where we
bring some of the most interesting Slack conversations to the public. Today
we're talking about finding out why a yarn package is installed, how to limit
values to a range in Ruby, and Rails application templates.

## Yarn `why`

Daniel Nolan learned that Yarn has [a command called `why`] which can be used to
find out what version of a module is being used and why it is installed.

```sh
$ yarn why jest
yarn why vx.x.x
[1/4] 🤔  Why do we have the module "jest"...?
[2/4] 🚚  Initializing dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
info Has been hoisted to "jest"
info This module exists because it's specified in "devDependencies".
info Disk size without dependencies: "1.29kB"
info Disk size with unique dependencies: "101.31kB"
info Disk size with transitive dependencies: "20.35MB"
info Amount of shared dependencies: 125
```

[a command called `why`]: https://classic.yarnpkg.com/en/docs/cli/why/

## Comparable#clamp

[Neil Carvalho] learned about the [Comparable#clamp method] in Ruby. This method
is used to limit a value to a given range of values. For example, if you have a variable
`x` with a value of 15 and you want to ensure that it never exceeds 10 or falls
below 5, you could use `x.clamp(5, 10)` to restrict it to that range. It also
works with a `Range` argument:

```rb
12.clamp(0..100)         #=> 12
-3.123.clamp(0..100)     #=> 0

'd'.clamp('a'..'f')      #=> 'd'
'z'.clamp('a'..'f')      #=> 'f'

-20.clamp(0..)           #=> 0
523.clamp(..100)         #=> 100
```

[comparable#clamp method]: https://docs.ruby-lang.org/en/3.1/Comparable.html#method-i-clamp

## Rails Application Templates

[Steve Polito] has gained a renewed interest in Rails Application Templates after
working on [Suspenders] during our annual hackathon and is considering exploring their
potential use as an alternative to Suspenders in appropriate cases.

He has started researching how application templates can require specific
arguments and enforce specific versions of Ruby and Rails. He recommends
checking out [David Copeland's template] and mentions that Rails also [supports a
.railsrc config file] that can be used to run the `rails new` command with default
arguments. Steve also notes that templates can be run against existing
applications.

[suspenders]: https://github.com/thoughtbot/suspenders
[david copeland's template]: https://github.com/davetron5000/rails-app-template-sustainable/blob/main/template.rb
[supports a .railsrc config file]: https://github.com/rails/rails/blob/ed81896765397ca98700a5853271308f9fe319a6/railties/lib/rails/generators/rails/app/USAGE#L5-L7

## Thanks

This edition was brought to you by Daniel Nolan, [Neil Carvalho], and [Steve Polito].
Thanks to all contributors! 🎉

[neil carvalho]: https://thoughtbot.com/blog/authors/neil-carvalho
[Steve Polito]: https://thoughtbot.com/blog/authors/steve-polito
