diff options
author | Jamis Buck <jamis@37signals.com> | 2007-01-22 22:53:38 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2007-01-22 22:53:38 +0000 |
commit | 1e9ce3c6a123baf773c89ef2324e9f3d17e2be52 (patch) | |
tree | 96943423983665fc8fee93a6ee95849aa15d7c28 /activesupport | |
parent | 59418618b9926ae0efebde29eb8765c4895635b9 (diff) | |
download | rails-1e9ce3c6a123baf773c89ef2324e9f3d17e2be52.tar.gz rails-1e9ce3c6a123baf773c89ef2324e9f3d17e2be52.tar.bz2 rails-1e9ce3c6a123baf773c89ef2324e9f3d17e2be52.zip |
Better docs for Object extensions (closes #7002)
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6011 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/misc.rb | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 7d42bf9e5c..aab84054cc 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Better docs for Object extensions [zackchandler, Jamis Buck] + * Fix that Dates couldn't be subtracted from Dates after [5940]. [Sam Stephenson] * Add Object#acts_like? and Time#acts_like_time? and Date#acts_like_date? to facilitate duck-typing. [Jamis Buck] diff --git a/activesupport/lib/active_support/core_ext/object/misc.rb b/activesupport/lib/active_support/core_ext/object/misc.rb index aae336e6f4..d82bb929a2 100644 --- a/activesupport/lib/active_support/core_ext/object/misc.rb +++ b/activesupport/lib/active_support/core_ext/object/misc.rb @@ -1,4 +1,4 @@ -class Object #:nodoc: +class Object # A Ruby-ized realization of the K combinator, courtesy of Mikael Brockman. # # def foo @@ -24,10 +24,30 @@ class Object #:nodoc: value end + # An elegant way to refactor out common options + # + # with_options :order => 'created_at', :class_name => 'Comment' do |post| + # post.has_many :comments, :conditions => ['approved = ?', true], :dependent => :delete_all + # post.has_many :unapproved_comments, :conditions => ['approved = ?', false] + # post.has_many :all_comments + # end + # + # Can also be used with an explicit reciever: + # + # map.with_options :controller => "people" do |people| + # people.connect "/people", :action => "index" + # people.connect "/people/:id", :action => "show" + # end + # def with_options(options) yield ActiveSupport::OptionMerger.new(self, options) end + # Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info. + # + # Account.find(1).to_json + # => "{attributes: {username: \"foo\", id: \"1\", password: \"bar\"}}" + # def to_json ActiveSupport::JSON.encode(self) end |