SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Apr 24, 2009, 23:09 #1
- 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?
-
Apr 25, 2009, 11:15 #2
- 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
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.
-
Apr 25, 2009, 22:05 #3
- Join Date
- Jun 2007
- Location
- Melbourne, Australia.
- Posts
- 121
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Apr 30, 2009, 07:02 #4
- Join Date
- Mar 2001
- Posts
- 3,537
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
cross posted on other forums
-
Apr 30, 2009, 07:13 #5
- Join Date
- Jun 2007
- Location
- Melbourne, Australia.
- Posts
- 121
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Last edited by superjacent; May 1, 2009 at 18:26.
Bookmarks