Reputation: 266940
puts 'hello' if some_id.nil? or (u.some_id == some_id)
Is this clear and the only way to write this logic in Ruby?
Upvotes: 0
Views: 144
Reputation: 24088
I don't think you can make it significantly more readable. You probably can decrease number of character, but it won't make it easier to read.
Another alternative would be eliminating nil
at all:
some_id = get_the_some_id or u.some_id #default to u.some_id
# some time later
puts 'hello' if u.some_id == some_id
Upvotes: 0
Reputation: 61011
Here's an alternative, although not necessarily any better:
puts 'hello' if [nil, u.some_id].contains? some_id
Upvotes: 1
Reputation: 81450
Have you checked whether there's an oror equivalent to the andand gem?
Upvotes: 0