From: Trans Date: 2005-04-07T12:34:41+09:00 Subject: Re: Garden RubyNuby Question on parameters in blocks vs. methods Daniel Amelang wrote: > Sorry, Trans, I just think that there are so many people on this list > that everyone figures someone else will answer. Yes, no doubt that's happening. Guess that's why I chirped up bit. > That said, your original post isn't _that_ old. If you're looking for > real-time help, go to #ruby-lang on irc.freenode.net. Oh, its not so much for me, though I have wondered about it myself in the past. It was a post on the Nuby page at Garden Wiki.... actually there are a number of questions there still waiting for an answer. I just noticed that someone posted a new one and I thought that maybe it would be good to work on them so I posted it here. See: http://www.rubygarden.org/ruby?RubyNuby Thanks for answering. You inspired some others too. I'll post a general response based on these posts to the wiki when the thread's done. > Although I think 1.9 will make them work more similarly that they do > now, I don't think they will ever work exactly alike. You can do some > stuff with block parameters that's pretty crazy. For example, you > don't have to 'accept' the arguments passed in: > > def doit > yield(1) > end > > doit { puts "Look ma, no arguments!" } Okay, so your syaing differences will remain b/c of how methods handle blocks --blocks of course can't take blocks in the same manner. > And you can expand arrays: > > def pass_array > yield([1,2]) > end > > pass_array {|(first, second)| puts "First element: #{first}"} Hmmm... the notation does allow for this additional functionality. Though I suspect this developed after the fact (i.e. after pipes were decided upon) but I'm not sure. > I haven't seen anything that says that methods will have this same > behavior (although they can do some of the same things using different > syntax) Anyone else? > > > As for the first. Why not "do (a,b) ... end" instead of "do |a,b| .... > > end" Well, without thinking about it to much, I imagine it is simply > > due to syntax ambiguities. > > I've wondered about this one before. It would be _possible_ to change > the method definition to use pipes instead of parans, and not have > ambiguities (I think), but that's a pretty significant language > change. I guess they were just born that way, and it's too late to > change. But the other way around? amethod { (x, y) puts "#{x} , #{y}" } That does seem ambiguious. T.