SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot superjacent's Avatar
    Join Date
    Jun 2007
    Location
    Melbourne, Australia.
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Methods and blocks - not that clear when blocks passed into methods

    Coming from other programming languages, notably Basic based, a little Java & C++, I find that passing blocks into methods is a little cryptic. What I mean is that when reading a method description (definition) there is no reference made to the fact that a block could be passed in as an argument. To me, it appears as if the method has to be read in conjunction with how the method is actually called in order to know if a block is passed or not. If my assertion is correct then the actual method call(s) in source code could be 100's of lines away from the method definition.

    Is this how things are or are there some techniques to smooth this process somewhat?

  2. #2
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can define a method like:

    Code:
    def foo a, b, &block
    end
    That specifies that a block can be passed in (though isn't required).

    But true, you can just call yield within a method without having an argument like that. Hopefully the description of the method though mentions it.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  3. #3
    SitePoint Zealot superjacent's Avatar
    Join Date
    Jun 2007
    Location
    Melbourne, Australia.
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by devbanana View Post
    You can define a method like:

    Code:
    def foo a, b, &block
    end
    That specifies that a block can be passed in (though isn't required).

    But true, you can just call yield within a method without having an argument like that. Hopefully the description of the method though mentions it.
    I prefer this way, at least it's explicit and suits the way my mind works.

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cross posted on other forums

  5. #5
    SitePoint Zealot superjacent's Avatar
    Join Date
    Jun 2007
    Location
    Melbourne, Australia.
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 7stud View Post
    cross posted on other forums
    A couple of points come to mind:-

    • What is your point?
    • What value did you add to this thread?
    Last edited by superjacent; May 1, 2009 at 18:26.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •