From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.86.23.1 with SMTP id 1cs280433fgw; Tue, 15 Sep 2009 04:51:14 -0700 (PDT) Received-SPF: pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.229.112.23 as permitted sender) client-ip=10.229.112.23; Authentication-Results: mr.google.com; spf=pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.229.112.23 as permitted sender) smtp.mail=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com; dkim=pass header.i=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com Received: from mr.google.com ([10.229.112.23]) by 10.229.112.23 with SMTP id u23mr4262898qcp.5.1253015473657 (num_hops = 1); Tue, 15 Sep 2009 04:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:received:x-sender:x-apparently-to :received:received:received:received-spf:received:mime-version :received:date:message-id:subject:from:to:content-type :content-transfer-encoding:reply-to:sender:precedence:x-google-loop :mailing-list:list-id:list-post:list-help:list-unsubscribe :x-beenthere-env:x-beenthere; bh=oXvzTGOXsRAS8yH6w40SW/2h0Znnw49PRBX+qKaQ3s4=; b=OffobEBkuYDd8UMUeo5quRNW0dxLCKSuPL64AMjDOL3Tup2omYNxvUJUDmfQewfa5F rTWEn5/k7M2kI1D02IgLaTRpeWAnmHe2HcLHQqqcxNg4Qj4rllK3YCR956M8B221bQkc h/DA60AIY6nSo2rSglepe6V4egNxtRbUlLdEQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:received-spf:authentication-results :mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding:reply-to:sender:precedence:x-google-loop :mailing-list:list-id:list-post:list-help:list-unsubscribe :x-beenthere-env:x-beenthere; b=QC/kZxGqhL4o+huxWR8lKkDaV3R3qQ3qPLQgi3gQxYZcqequ7gEDYEvhjy+31mSboU 2QzeKDEjv0SL8SWW8Fd7Q8D0i1vsODclJjoTL8IlfYjB4FNEgmK2DS9H6O8eszpdMu56 SxPsQ3TH4cbKnl8iQjqU2ZxiOCr/dpA8V+/f0= Received: by 10.229.112.23 with SMTP id u23mr600911qcp.5.1253015473588; Tue, 15 Sep 2009 04:51:13 -0700 (PDT) Received: by 10.176.13.37 with SMTP id 37gr1666yqm.0; Tue, 15 Sep 2009 04:51:01 -0700 (PDT) X-Sender: ibc@aliax.net X-Apparently-To: rack-devel@googlegroups.com Received: by 10.204.161.203 with SMTP id s11mr150306bkx.37.1253015459985; Tue, 15 Sep 2009 04:50:59 -0700 (PDT) Received: by 10.204.161.203 with SMTP id s11mr150305bkx.37.1253015459956; Tue, 15 Sep 2009 04:50:59 -0700 (PDT) Return-Path: Received: from mail-fx0-f222.google.com (mail-fx0-f222.google.com [209.85.220.222]) by gmr-mx.google.com with ESMTP id 16si718453bwz.4.2009.09.15.04.50.59; Tue, 15 Sep 2009 04:50:59 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.222 is neither permitted nor denied by best guess record for domain of ibc@aliax.net) client-ip=209.85.220.222; Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 209.85.220.222 is neither permitted nor denied by best guess record for domain of ibc@aliax.net) smtp.mail=ibc@aliax.net Received: by mail-fx0-f222.google.com with SMTP id 22so2724784fxm.12 for ; Tue, 15 Sep 2009 04:50:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.22.4 with SMTP id l4mr2588820fab.37.1253015456446; Tue, 15 Sep 2009 04:50:56 -0700 (PDT) Date: Tue, 15 Sep 2009 13:50:56 +0200 Message-ID: Subject: Issue using Ruby1.9 (instance_eval in /lib/rack/builder.rb) From: =?UTF-8?Q?I=C3=B1aki_Baz_Castillo?= To: rack-devel@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Reply-To: rack-devel@googlegroups.com Sender: rack-devel@googlegroups.com Precedence: bulk X-Google-Loop: groups Mailing-List: list rack-devel@googlegroups.com; contact rack-devel+owner@googlegroups.com List-Id: List-Post: List-Help: List-Unsubscribe: , X-BeenThere-Env: rack-devel@googlegroups.com X-BeenThere: rack-devel@googlegroups.com Using Ruby1.9 there is an issue related to instance_eval() method which behaves different than in 1.8. Let me show this example: --------myapp.rb------------------------ class MyRack MY_VAR =3D "helloooo" def self.create Rack::Builder.new do map "/" do puts "[1] MY_VAR =3D #{MY_VAR}" <----- [1] (line 20) run Proc.new { |env| puts "[2] MY_VAR =3D #{MY_VAR}" <----- [2] (line 22) [ 200, {"Content-Type" =3D> "text/plain"}, ["Yeah"] ] } end end end end rack_core =3D MyRack.create Rack::Handler::Thin.run rack_core ---------------------------------------- This works great in Ruby1.8. However, in Ruby1.9 I get this error: /myapp.rb:20:in `block (2 levels) in core': uninitialized constant Rack::Builder::MY_VAR (NameError) from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/bui= lder.rb:29:in `instance_eval' from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/bui= lder.rb:29:in `initialize' from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/bui= lder.rb:46:in `new' from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/bui= lder.rb:46:in `map' from /root/svn_local_copies/OpenXDMS/trunk/lib/rack/core.rb:41:in `block in core' from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/bui= lder.rb:29:in `instance_eval' from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/bui= lder.rb:29:in `initialize' If I remove line 20, then it would in runtime in line 22 (when "run" is invoked for a incoming request). The only solution for it to work in 1.9 is to add ALL the Module/Class namespace for ALL the modules/classes: Rack::Builder.new do map "/" do puts "[1] MY_VAR =3D #{::MyRack::MY_VAR}" <----- [1] (li= ne 20) run Proc.new { |env| puts "[2] MY_VAR =3D #{::MyRack::MY_VAR}" <----- [2] (line 22) [ 200, {"Content-Type" =3D> "text/plain"}, ["Yeah"] ] } end end It's VERY important to note that if I use "MyRack::MY_VAR" instead of "::MyRack::MY_VAR" then it would *also* fail in Ruby1.9: `block (2 levels) in core': uninitialized constant Rack::Builder::MyRack (NameError) It seems that using instance_eval in Ruby1.9 a class/module is just looked for into the class/module executing the instance_eval and doesn't look on top of it. Regards. --=20 I=C3=B1aki Baz Castillo