From ruby-talk-admin@ruby-lang.org Fri Dec 16 02:26:17 2005 Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (8.12.3/8.12.3/Debian-6.6) with ESMTP id jBFHQHZk029436; Fri, 16 Dec 2005 02:26:17 +0900 Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 1DF2E5A91; Fri, 16 Dec 2005 02:26:22 +0900 (JST) Received: from localhost (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 1FC3AF0489D; Fri, 16 Dec 2005 02:26:22 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id C4ED6F0489C; Fri, 16 Dec 2005 02:26:20 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [210.163.138.100]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id BB648630025; Fri, 16 Dec 2005 02:26:20 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by beryllium.ruby-lang.org (Postfix) with ESMTP id A834533DCA; Fri, 16 Dec 2005 02:26:19 +0900 (JST) Received: from localhost (beryllium.ruby-lang.org [127.0.0.1]) by beryllium.ruby-lang.org (Postfix) with ESMTP id C778533DCC for ; Fri, 16 Dec 2005 02:26:10 +0900 (JST) Received: from beryllium.ruby-lang.org ([127.0.0.1]) by localhost (beryllium.ruby-lang.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 12371-03 for ; Fri, 16 Dec 2005 02:26:10 +0900 (JST) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.202]) by beryllium.ruby-lang.org (Postfix) with ESMTP id 4FC7F33DCA for ; Fri, 16 Dec 2005 02:26:10 +0900 (JST) Received: by zproxy.gmail.com with SMTP id 8so411426nzo for ; Thu, 15 Dec 2005 09:26:05 -0800 (PST) Received: by 10.36.72.20 with SMTP id u20mr2059920nza; Thu, 15 Dec 2005 09:26:05 -0800 (PST) Received: by 10.36.71.19 with HTTP; Thu, 15 Dec 2005 09:26:05 -0800 (PST) Delivered-To: ruby-talk@ruby-lang.org Date: Fri, 16 Dec 2005 02:26:11 +0900 Posted: Thu, 15 Dec 2005 11:26:05 -0600 From: C Erler Reply-To: ruby-talk@ruby-lang.org Subject: Re: Assigning a block to a variable in Ruby To: ruby-talk@ruby-lang.org (ruby-talk ML) Message-Id: <6a9c61b10512150926s5ba6228ci@mail.gmail.com> In-Reply-To: <1134665773.927049.245200@z14g2000cwz.googlegroups.com> References: <1134665773.927049.245200@z14g2000cwz.googlegroups.com> X-ML-Name: ruby-talk X-Mail-Count: 75 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-talk-ctl@ruby-lang.org; help= X-Original-To: ruby-talk@ruby-lang.org DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=EBuFjE0MnUlrQzc7OLbFQ8Y8hhLIPcXFzRMDYAUHQ3BQFXeKdq8tEw12+uNwaEk8TpJWjj/b0CoXbKE35F9o0PVlRh27XZKwkPDxdwfXA7dHuSM+N1sl6dEk30bpChxxRAMuC2YrIHdiaf4qPw35J+PD6XOBduZ9m6DX7+jfz9I= Content-Disposition: inline X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ruby-lang.org X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on beryllium.ruby-lang.org X-Spam-Level: X-Spam-Status: No, score=-11.7 required=7.0 tests=AWL,BAYES_00,BLARS00, BLARS_SPAM00,CONTENT_TYPE_PRESENT,MIMEQENC,QENCPTR1,QENCPTR2, RCVDFRMLOCALIP,RCVD_BY_IP,RCVD_IN_BLARS,RCVD_IN_BLARS_HOOPS, RCVD_IN_BLARS_SPAM autolearn=ham version=3.0.3 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Precedence: bulk Lines: 31 List-Id: ruby-talk.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: X-Virus-Scanned: by AMaViS snapshot-20020531 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by blade.nagaokaut.ac.jp id jBFHQHZk029436 Sorry, missed this part : On 15/12/05, ajmayo@my-deja.com wrote: > It is also unclear, how, then, I pass down a block as an argument and > then in turn pass it again to a child routine. There are two ways to do this: the block variable way and the normal parameter way. If you want to pass it as a block (it has to be the last parameter) : def method other_parameters, &the_block use_the_block_as_a_regular_parameter_for_this_method(the_block) use_the_block_as_a_block_for_this_method(&the_block) end method param { |vars| block } If you want to pass it as a normal parameter (it doesn't have to be the last parameter) : def method other_parameters, the_parameter use_the_block_as_a_regular_parameter_for_this_method(the_parameter) use_the_block_as_a_block_for_this_method(&the_parameter) end my_proc = proc { |vars| block } method param, my_proc So, basically, & is the thing that makes a parameter the block (when you're defining the method and when you're calling it).