>From Ruby Syntax point of view, you could write something like this:

 [1,2,3].wrap_results_with(UserDelegator, &p)

where the method looks like:

def block_wrap_with(klass, &block)
  map do |a|
    result = yield a, klass
  end
end

and

p = lambda  { |m, klass| klass.new(m) }

possibly, you could put the block definition inside the method

def block_wrap_with(klass)
  p = lambda  { |m, klass| klass.new(m) }
  map do |a|
     p.call(a, klass)
  end
end



On Wed, Jun 13, 2012 at 11:38 PM, Christopher J. Bottaro
<[email protected]> wrote:
> I want to define a method on ActiveRelation that works like the
> following...
>
> users = User.where(...).wrap_results_with(UserDelegator)
>
> which would be equivalent to:
>
> users = Users.where(...).collect{ |user| UserDelegator.new(user) }
>
> How/where would I define wrap_results_with?
>
> I just need a point in the right direction to get my foot in the door.
> Thanks.
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to