Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Keep if clauses side-effect free (teamten.com)
2 points by a_w 9 months ago | hide | past | favorite | 1 comment


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?

```




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: