---
title: "关于returning"
author: "fei1985"
date: "2010-04-09T23:52:20Z"
tags: []
categories: ["编程语言"]
slug: "returning"
draft: false
lastmod: "2010-04-09T23:52:20Z"
id: 640185
url: "https://1985.iteye.com/blog/640185"
---

在beast的记录中看到一个方面中用到returning的用法。

 

```
 def reply(topic, body)
    returning topic.posts.build(:body => body) do |post|
      post.forum = topic.forum
      post.user  = self
      post.save
    end
  end
```

 有点不是很理解。在google中收到这篇文章是关于returning的说明的

http://weblog.jamisbuck.org/2006/10/27/mining-activesupport-object-returning

 

 

```
def returning(value)
  yield(value)
  value
end
```