Reputation: 2975
I have a statement checking if a string contains another; if it doesn't, it runs some code. I don't think I'm doing it in a very optimised way. Here is a code snippet:
if blocks_in_progress.include? ('|' + blocks[i])
else
block = blocks[i]
break
end
Upvotes: 0
Views: 3338
Reputation: 118289
A one liner:
break block = blocks[i] unless blocks_in_progress.include? ('|' + blocks[i])
Upvotes: 3
Reputation: 770
Bit of a Ruby newbie here, but as far as I understand it, the following is the preferred way:
unless blocks_in_progress.include? ('|' + blocks[i])
block = blocks[i]
break
end
Source: https://github.com/bbatsov/ruby-style-guide (syntax section)
Upvotes: 4