Mmm... higher order code

Mmm… I love this programming language.

I’ve just written the following:

def perform_action_without_filters
scope_hash = {:find => {:conditions => “blog_id = #{this_blog.id}”},
:create => {:blog_id => this_blog.id}}
blog_scoped_model_classes.inject(lambda {super}) do |block, klass|
lambda { klass.with_scope(scope_hash, &block) }
end.call
end

And I fully expect it to work. Do you think I’ve spent to long
programming in lisp?

On 3/21/06, Piers C. [email protected] wrote:

end

And I fully expect it to work. Do you think I’ve spent to long
programming in lisp?

Can you decipher that for those of us a bit newer to things? :slight_smile:

  • Rob


http://www.robsanheim.com/

“Rob S.” [email protected] writes:

end.call

end

And I fully expect it to work. Do you think I’ve spent to long
programming in lisp?

Can you decipher that for those of us a bit newer to things? :slight_smile:

If I tell you that the ‘inject’ bit is replacing something like:

Content.with_scope(scope_hash) do
Article.with_scope(scope_hash) do
Comment.with_scope(scope_hash) do
Trackback.with_scope(scope_hash) do
super
end
end
end
end

does it help?

Other helpers:
lambda is roughly equivalent to Proc.new

This:
foo = lambda { “Bibble” }
some_method(&foo)

is roughly equivalent to:

some_method() {"Bibble"}

The rest is just a matter of reading the docs :slight_smile: