The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Blocks

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Keith Ray

Posts: 658
Nickname: keithray
Registered: May, 2003

Keith Ray is multi-platform software developer and Team Leader
Blocks Posted: Sep 28, 2005 8:38 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by Keith Ray.
Original Post: Blocks
Feed Title: MemoRanda
Feed URL: http://homepage.mac.com/1/homepage404ErrorPage.html
Feed Description: Keith Ray's notes to be remembered on agile software development, project management, oo programming, and other topics.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Keith Ray
Latest Posts From MemoRanda

Advertisement

Ruby, calling a method with a block argument:


    anObject.methodTakingBlock { someObj.doSomethingHere }

or


    anObject.methodTakingBlock do
        someObj.doSomethingHere
    end

Smalltalk, calling a method with a block argument:


    anObject methodTakingBlock: [ someObj doSomethingHere ].

Ruby, implementing a method that takes a block argument (the lack of a named block variable and the "yield" keyword are a bit confusing, particularly if you associate "yield" with threads, which are not in play here.)


    def methodTakingBlock
        yield
    end

Smalltalk, implementing a method that takes a block argument.


    methodTakingBlock: aBlock
        aBlock value.

Ruby, calling a method with a block argument that takes two argument itself:


    anObject.methodTakingBlock { 
        |aVar, bVar| someObj.doSomethingHere(aVar, bVar) }

or


    anObject.methodTakingBlock do |aVar, bVar|
        someObj.doSomethingHere(aVar, bVar)
    end

Smalltalk, calling a method with a block argument that takes two arguments itself:


    anObject methodTakingBlock: [ :aVar :bVar | 
        someObj doSomethingHere: aVar andHere: bVar ].

Ruby, implementing a method that takes a block argument, giving the block the values 12 and 13 for the block's own arguments.


    def methodTakingBlock
        yield 12, 13
    end

An Ruby alternative syntax where the block argument is converted to a Proc object and is accessible via a named parameter:


    def methodTakingBlock(&aProc)
        aProc.call(12,13)
    end

Smalltalk, implementing a method that takes a block argument, giving the block values 12 and 13 for its own arguments.


    methodTakingBlock: aBlock
        aBlock value: 12 value: 13.

Read: Blocks

Topic: Wait a sec Previous Topic   Next Topic Topic: Sounds like a content hit

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use