Forum: Typo Mmm... higher order code

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0196ff65610046d2f8ba58bc4a45f144?d=identicon&s=25 Piers Cawley (Guest)
on 2006-03-21 18:30
(Received via mailing list)
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?
Df5e7adb20adae6c120b04e7cafb15a0?d=identicon&s=25 Rob Sanheim (Guest)
on 2006-03-21 18:42
(Received via mailing list)
On 3/21/06, Piers Cawley <pdcawley@bofh.org.uk> 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? :)

- Rob


--
http://www.robsanheim.com/
http://www.ajaxian.com/
0196ff65610046d2f8ba58bc4a45f144?d=identicon&s=25 Piers Cawley (Guest)
on 2006-03-21 19:50
(Received via mailing list)
"Rob Sanheim" <rsanheim@gmail.com> 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? :)

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 :)
This topic is locked and can not be replied to.