resubject icon indicating copy to clipboard operation
resubject copied to clipboard

Presenting a Struct does not work

Open terlar opened this issue 12 years ago • 4 comments
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.

terlar avatar Jan 31 '13 13:01 terlar

Unfortunately this fix won't work either since Struct apparently is an Enumerable. :crying_cat_face:

terlar avatar Jan 31 '13 15:01 terlar

Just checked and @terlar is right

U = Struct.new(:a)
U.ancestors
=> [U, Struct, Enumerable, Object, PP::ObjectMixin, Kernel, BasicObject]

felipeelias avatar Jan 31 '13 15:01 felipeelias

This is bad since there's no real workaround then, only providing both present_one and present_all

darthdeus avatar Jan 31 '13 20:01 darthdeus

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

felipeelias avatar Jan 31 '13 22:01 felipeelias