resubject
resubject copied to clipboard
Presenting a Struct does not work
trafficstars
I have this object:
class MyObject < Struct.new(:title, :description, :count)
end
I present with:
present(my_object)
Now it tries to present title, description and count instead of presenting the object.
Unfortunately this fix won't work either since Struct apparently is an Enumerable. :crying_cat_face:
Just checked and @terlar is right
U = Struct.new(:a)
U.ancestors
=> [U, Struct, Enumerable, Object, PP::ObjectMixin, Kernel, BasicObject]
This is bad since there's no real workaround then, only providing both present_one and present_all
Also, there are few other workarounds
ThePresenter.new(Struct.new(...), view_context) # if in a controller
# when array
ThePresenter.all([Struct, Struct], view_context)
The other way would check if the class is some sort of struct, or creating helpers to expose the Builder's present methods