Live data from Hacker News

Keep if clauses side-effect free

teamten.com

1–2 of 2 posts

Re: Keep if clauses side-effect free

#2
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?

```