Is there a way to have an iterator that iterates anyways even when the object is nil?
For example, I’d like to strip my views from my application and create a dummy app for a designer.
So I would like it to iterate or loop.
How can this be done?
I’ve just found a way of doing it
<%
(@messages.count == 0 ? Array.new(5).map { Message.new } : @messages.each).each do |m|
%>
You should be able to use something like this:
So what this does is to iterarte over dummy things if
@thingswasnil, otherwise only iterate over@things.EDIT
A more concise version of
dummy_things, as mentioned by Victor, would be something like this: