---
title: 'This week in #dev (Apr 28, 2023)'
teaser: 'The Today I Learned edition.

  '
tags: this week in dev,til,ruby,rails,git
author: thoughtbot
published_on: 2023-05-09
---

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.
This is the Today I Learned edition.

## Active Record's `rewhere`

Matheus Sales learned about the
[rewhere](https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-rewhere)
method in Active Record. It’s a query method that allows you to change a
previously set `where` condition for a given attribute instead of appending to
that condition.

```rb
Post.where(published: true).rewhere(published: false) # => WHERE `published` = 0
```

It can be handy for overriding a [`default_scope`] or when building an index page
with a couple of filters, and one of those must override previous ones applied.

There's also [`reorder`] and [`reselect`], Neil Carvalho adds.

[`default_scope`]: https://api.rubyonrails.org/classes/ActiveRecord/Scoping/Default/ClassMethods.html#method-i-default_scope
[`reorder`]: https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-reorder
[`reselect`]: https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-reselect

## Stashing Untracked Files

Steve Polito shares that he learns that it's possible to
stash untracked files with `git stash --untracked`.

```sh
$ git status
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        README.md
​
$ git stash
No local changes to save
​
$ git stash --include-untracked
Saved working directory and index state WIP on...
```

## Ruby's `Date.parse` Format Preference

Neil Carvalho discovered that Ruby's [`Date.parse`] prefers the DD/MM/YYYY format
over MM/DD/YYYY.

```rb
date = Date.parse "02/01/2023"
# => #<Date: 2023-01-02 ((2459947j,0s,0n),+0s,2299161j)>

date.day
# => 2
date.month
# => 1
```

[`Date.parse`]: https://docs.ruby-lang.org/en/3.2/Date.html#method-c-parse

## Today I Learned

In a TIL-meta fashion, Sarah Lima shares that she learned about thoughtbot's [TIL
repo].

[TIL repo]: https://github.com/thoughtbot/til

## Thanks

This edition was brought to you by: [Matheus Sales], [Neil Carvalho], [Sarah
Lima], and [Steve Polito]. Thanks to all contributors! 🎉

[Matheus Sales]: https://thoughtbot.com/blog/authors/matheus-sales
[Neil Carvalho]: https://thoughtbot.com/blog/authors/neil-carvalho
[Sarah Lima]: https://thoughtbot.com/blog/authors/sarah-lima
[Steve Polito]: https://thoughtbot.com/blog/authors/steve-polito
