From: Marc Dominik Migge Date: 2006-06-27T23:50:13+09:00 Subject: Re: newbie doesn't understand why's example ------=_Part_49564_9385347.1151419809799 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Helge's example would recursivly call itself. As mentioned before .collect returns an object of class Array. So calling collect do |item| ... end.join(sep) # "end" ends the do block is essentially the same as collect { |item| ... }.join(sep) In each case collect evaluates to [item1, item2, ...] # an Array object of items So the result is the same as if you had [item1, item2, ...].join(sep) # calls Array#join not ArrayMain#join There is nothing special in the Ruby syntax here. In Java you could do the same thing, e.g. funtionThatReturnsAnArray().length() The main difference between the two languages in this matter is that in Ruby you can call methods on what Java people might call "primitives type constants", e.g. 5.times {puts "hello"} Maybe the "blocks" (the stuff between "{" and "}" or, alternativley "do" and "end") confused you here. Marc Migge On 6/27/06, dave rose wrote: > > all of you, have all been some help here...but i'm still confused and > i'm not trying split hairs here but what's in the syntax of > end.join(sep) or foo=foo.join(sep) that ruby doesn't recursively recall > arraymine's join.... another words based on previous why's (or other > tutorials that i've seen) > def fact(n) > if n=1 return 1 > else > return n*fact(n-1)<<< 'end.join(sep)' > end > end > it's still recalling the function's name.... > Please give an example where the arraymine (or any other example) join > WOULD recursively recall itself so that i can see the difference.... > another words how differently is Arraymine inherenting the Array join > method and/or extending it and at what point does ruby know the > difference????? just by the syntax alone???? > Marc Dominik Migge wrote: > > Read Guy's post again. It's all there. The two occurrences of .join call > > completely different functions. His one-liner just provides proof of > > what he > > has written above it. > > > > Marc Migge > > > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_49564_9385347.1151419809799--