1.I can't find an elegant way to write this code:
if array.empty? # process empty array else array.each do |el| # process el end end
I'd like to have one loop, without writing array
twice. I read this, but there is no solution good enough.
2. I am actually in an HAML template. Same question.
- if array.empty? %p No result - else %ul - array.each do |el| %li el
What about?
array.each do |x| #... puts "x",x end.empty? and begin puts "empty!" end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With