How can I refactor the following code to avoid repetition?
r = @lots.fetch @lots.keys.sample
until (neighbours r)
r = @lots.fetch @lots.keys.sample
end
I basically have a new r
object that is picked randomly and I need to pick r
till the selected one doesn't respond to certain criteria (neighbours r
). How can I refactor it to avoid the repetition of getting r and keep getting it till a condition is reached? Thanks