Settings

Theme

Keep if clauses side-effect free

teamten.com

2 points by a_w 7 months ago · 1 comment

Reader

a_wOP 7 months 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?

```

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection