Skip to content
cavalle edited this page Jan 7, 2013 · 1 revision

Version #10

class Commenter
  def initialize(person)
    @person = person
  end

  def recent_comments
    @person.comments.where("created_at > ?", 3.days.ago)
  end

  def post_comment(text)
    @person.comments.create(:body => text)
  end

  def update_comment(new_text)
    raise "Comment not owned by this person" unless comment.author == @person

    comment.update_attribute(:body, new_text)
  end
end

Clone this wiki locally