Google Groups Home
Help | Sign in
.each { |m| delegate m, :to => :published_at }
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Neeraj Kumar  
View profile
 More options Jan 1 2007, 1:37 am
From: "Neeraj Kumar" <neeraj....@gmail.com>
Date: Mon, 1 Jan 2007 01:37:25 -0500
Local: Mon, Jan 1 2007 1:37 am
Subject: [:year, :month, :day].each { |m| delegate m, :to => :published_at }

Given below is a model from mephisto blogging tool.

class Content < ActiveRecord::Base
  filtered_column :body, :excerpt
  belongs_to :user, :with_deleted => true
  belongs_to :site
  [:year, :month, :day].each { |m| delegate m, :to => :published_at }
end

I couldn't understand the last line.

Anyone care to explain what's happening in the last line.

Thanks.
- Neeraj


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tom Fakes  
View profile
(2 users)  More options Jan 1 2007, 2:52 am
From: "Tom Fakes" <t...@tomandlisa.us>
Date: Sun, 31 Dec 2006 23:52:11 -0800
Local: Mon, Jan 1 2007 2:52 am
Subject: Re: .each { |m| delegate m, :to => :published_at }
This is the quick way of writing the following:

  def year
    published_at.year
  end

  def year=(y)
    published_at.year = y
  end

  # Same for month and day

The 'delegate' method allows you to delegate a member access to a
member with the same name on a different member object, so you can
avoid writing 'content.published_at.year'


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Duane Johnson  
View profile
(1 user)  More options Jan 1 2007, 11:43 am
From: Duane Johnson <duane.john...@gmail.com>
Date: Mon, 1 Jan 2007 09:43:04 -0700
Local: Mon, Jan 1 2007 11:43 am
Subject: Re: [Rails] Re: .each { |m| delegate m, :to => :published_at }
Thanks, Tom, that's really handy.

I was wondering where this 'delegate' method is defined, so I looked  
it up and found it in ActiveSupport--it's a method defined in the  
Module class.  Pretty tricky :)

Available here, if anyone else is interested:
   activesupport/lib/active_support/core_ext/module/delegation.rb

Duane Johnson
(canadaduane)
http://blog.inquirylabs.com/

On Jan 1, 2007, at 12:52 AM, Tom Fakes wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google