Ok, lets do this step by step.
Firstly, you define a helper-method which assigns @designer
as default. This is the reason, why you can call it without any arguments in your view:
<% designer_status_for do |status| %>
# more code
Then, DesignerStatus
is the actual presenter, which is a different class than Designer and creates a total new object, but which is sort of based on the @designer
object. So, presenter
is a new object of type DesignerStatus
block_given?
, as you might guess, checks, if this object should be passed to a block or if it should work as a normal object. This is most likely the tricky part where you are having trouble understanding. So let me explain it the other way around. You can call something like this
designer_status_for.some_presenter_method
in your view, and it would work. It works, because no block is given and a designer
object is returned (in other words, the else
part is triggered), on which you can call some_presenter_method
directly. So, you could use that all throughout your view, and you would be just fine.
However, there is an even better option, namely yield
this object into a block. The yield
option is what makes this code-snippet
<% designer_status_for do |status| %>
status.some_presenter_method
<% end %>
possible in the first place. What this basically says is "take that presenter object, assign it to a variable called status
and make this variable available to the block.
So, if you are having a hard time to wrap your head around yield
right now, don't worry to much about it. Just call any method on designer_status_for
itself. The benefit of using the block over the object itself is the fact, that your code becomes less brittle, but that's sort of another topic.