DEV Community

Discussion on: SQL query from the view: considered hazardous!

Collapse
 
kinnalru profile image
Samoilenko Yuri • Edited

But where to define interface class PostListItem?

Collapse
 
kgilpin profile image
Kevin Gilpin • Edited

This is all you need to do to define this type with the listed attributes:

PostListItem = Struct.new(:body, :username, :attachments)
Enter fullscreen mode Exit fullscreen mode

It's now a Ruby class with a defined initialize method and many other convenience methods such as to_h.