From: "Jesús Gabriel y Galán" Date: 2010-07-30T15:20:44+09:00 Subject: Re: Problem with a lambda not executing immediately On Thu, Jul 29, 2010 at 10:38 PM, Fernando Perez wrote: > Hi, > > I'm using the paperclip plugin for one of my rails app, but my problem > is pure Ruby. I'm not good enough with Ruby and lambdas so I need your > advice. > > Here is the code I am trying to make work: > > class Asset < ActiveRecord::Base > >  has_attached_file :data, :styles => { >    :theora => [:format => :ogv, :processors => lambda {|a| a.video? ? > [:video_converter] : []}}] > } > > end > > > What fails is the lambda, because in Paperclip behind the scenes this is > what happens: > > @var = style.processors.inject(something) do |file, processor| > ... > end > > style.processors has received the lambda defined earlier. > > > And I get the following error message: > > NoMethodError (undefined method `inject' for #) > > > So how can I fix it, and after that which book or resources can I read > to get proficient in such dynamic coding practice? Currently in use > blocks all the time ([array].each { ...}) without really mastering them. I have no idea about paperclip, but looking at the above snippets style.processor should be an Enumerable (which is where inject is defined), for example an array. Given that the key in the hash is :processors (in plural) I would assume that the value should be an array of processors. So, even if you only have one lambda, can you try this: class Asset < ActiveRecord::Base has_attached_file :data, :styles => { :theora => [:format => :ogv, :processors => [lambda {|a| a.video? ? [:video_converter] : []}]}] } Jesus.