From ruby-talk-admin@ruby-lang.org Fri Dec 16 02:33:25 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 jBFHXPZk029646; Fri, 16 Dec 2005 02:33:25 +0900 Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 0777D5935; Fri, 16 Dec 2005 02:33:30 +0900 (JST) Received: from localhost (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 0E6D8F0489C; Fri, 16 Dec 2005 02:33:30 +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 C751AF0488C; Fri, 16 Dec 2005 02:33:28 +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 C1A9C630025; Fri, 16 Dec 2005 02:33:28 +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 443EE33D7A; Fri, 16 Dec 2005 02:33:27 +0900 (JST) Received: from localhost (beryllium.ruby-lang.org [127.0.0.1]) by beryllium.ruby-lang.org (Postfix) with ESMTP id 0267233DC2 for ; Fri, 16 Dec 2005 02:33:18 +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 13283-02 for ; Fri, 16 Dec 2005 02:33:17 +0900 (JST) Received: from utopia.poly.edu (utopia.poly.edu [128.238.3.21]) by beryllium.ruby-lang.org (Postfix) with ESMTP id 5E1A233D7A for ; Fri, 16 Dec 2005 02:33:16 +0900 (JST) Received: from [128.238.79.59] ([128.238.79.59]) by utopia.poly.edu (8.13.1/8.13.1) with ESMTP id jBFHWtcR029040 for ; Thu, 15 Dec 2005 12:33:06 -0500 (EST) Delivered-To: ruby-talk@ruby-lang.org Date: Fri, 16 Dec 2005 02:33:18 +0900 Posted: Thu, 15 Dec 2005 12:32:51 -0500 From: Logan Capaldo 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: In-Reply-To: <1134665773.927049.245200@z14g2000cwz.googlegroups.com> References: <1134665773.927049.245200@z14g2000cwz.googlegroups.com> X-ML-Name: ruby-talk X-Mail-Count: 77 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-Mailer: Apple Mail (2.746.2) X-Original-To: ruby-talk@ruby-lang.org X-Virus-Status: Clean 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=-4.0 required=7.0 tests=AWL,BAYES_00, CONTENT_TYPE_PRESENT,HTML_MESSAGE,MIMEQENC,MULTIPART_ALTERNATIVE, QENCPTR1,RCVDFRMLOCALIP,TOOLONGSTR,X_MAILER_PRESENT autolearn=no version=3.0.3 Mime-Version: 1.0 (Apple Message framework v746.2) Content-Type: multipart/alternative; boundary=Apple-Mail-10--405534925 Precedence: bulk Lines: 94 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 --Apple-Mail-10--405534925 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed On Dec 15, 2005, at 11:57 AM, ajmayo@my-deja.com wrote: > Also, I presume Ruby is a forward-referencing language only, unlike > Javascript, where I can declare a function after code which calls it. > Ruby didn't seem to like that much. How did you run into problems with this? irb(main):024:0> def a(x) irb(main):025:1> g(x) irb(main):026:1> end => nil irb(main):027:0> def g(x) irb(main):028:1> puts x irb(main):029:1> end => nil irb(main):030:0> a(5) 5 => nil As regards your other question def bar(z) puts z end a = lambda { |x| puts x } bar(a) Alternatively to pass a block to a function without yield... def bar(&block) block.call end bar { puts "hi!" } #=> prints hi --Apple-Mail-10--405534925--