Keep if clauses side-effect free

1 a_w 1 5/24/2025, 8:14:57 PM teamten.com ↗

Comments (1)

a_w · 6h ago
I do this often:

```ruby

if (user = User.find_by(email: 'abc@example.com'))

  user.update(status: 'active')
end

```

Is it better to do this instead?

```ruby

user = User.find_by(email: 'abc@example.com')

user.update(status: 'active') if user.present?

```