Ruby Idiom | January 13th, 2008
I saw this in the RSpec code while I was writing tests today:
[self.errors.on(attribute)].flatten.compact
It struck me as a very concise way to handle the case where it is either a scalar or an array (assuming you don’t care if the returned array is nested). It might get you out of some gymnastics trying to account for both cases.
Leave a Reply
Moderation Active: Old stuff here... Therefore your comment on this post will be moderated (i.e. don't submit twice !)