1日1%成長するブログ

毎日成長するために仕事/プライベートで得た学びをアウトプットするブログです

2020-05-01から1日間の記事一覧

Rubyのアクセサメソッドを使ってEntityクラスを作ってAPIのレスポンスに使う

class HogePostsEntity attr_reader :author, :comments def initialize(post) @author = post.author @comments = post.comments end def self.collection(posts) posts.map { |post| new(post) } end end こんな感じでシンプルにEntity用のクラスを作れた…