From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.86.23.1 with SMTP id 1cs280751fgw; Tue, 15 Sep 2009 04:59:50 -0700 (PDT) Received-SPF: pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.224.125.78 as permitted sender) client-ip=10.224.125.78; Authentication-Results: mr.google.com; spf=pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.224.125.78 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.224.125.78]) by 10.224.125.78 with SMTP id x14mr4454379qar.13.1253015990147 (num_hops = 1); Tue, 15 Sep 2009 04:59:50 -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:dkim-signature :domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject: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=0AOpJ878NboAdYdw5bhuaQLgzUq3fD2MvNMfVvv/7rU=; b=LIuAtLtj02tm0H8bC8s+/YIF6wB3AyIiUO0zlQ0lo+CzObbSpV+ENvnmTNFB9w8xXx ugIy6hCcOvW3bSnkWS/6KRbYFvfG1tXPQZvb4dTDsdU/RUT8RmOQeiERuiN6L0fM/t78 lbgq2wF5kv9aADqyNxSbV6f03yCpq5LvKy7+E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:received-spf:authentication-results :dkim-signature:domainkey-signature:mime-version:in-reply-to :references:from:date:message-id:subject: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=pw4aBcRawznbCjb0DuHuPquaYtmYxKZXZyfpuAEqeuCNqQ9THgfJliAdzy1XYKbvdq D4YGARdBQ1tidJyyb3mW4MjmtjI1nWtNKUspEQJmladotRfDgTMrVk+eV+i9lIZICkyT U+niVPUXDrQ3rHsvzbv47iqsltLpu0epk94Hc= Received: by 10.224.125.78 with SMTP id x14mr638698qar.13.1253015990077; Tue, 15 Sep 2009 04:59:50 -0700 (PDT) Received: by 10.177.112.39 with SMTP id p39gr1667yqm.0; Tue, 15 Sep 2009 04:59:45 -0700 (PDT) X-Sender: judofyr@gmail.com X-Apparently-To: rack-devel@googlegroups.com Received: by 10.86.13.12 with SMTP id 12mr187263fgm.22.1253015983455; Tue, 15 Sep 2009 04:59:43 -0700 (PDT) Received: by 10.86.13.12 with SMTP id 12mr187262fgm.22.1253015983434; Tue, 15 Sep 2009 04:59:43 -0700 (PDT) Return-Path: Received: from mail-bw0-f223.google.com (mail-bw0-f223.google.com [209.85.218.223]) by gmr-mx.google.com with ESMTP id 5si391782fge.11.2009.09.15.04.59.42; Tue, 15 Sep 2009 04:59:42 -0700 (PDT) Received-SPF: pass (google.com: domain of judofyr@gmail.com designates 209.85.218.223 as permitted sender) client-ip=209.85.218.223; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of judofyr@gmail.com designates 209.85.218.223 as permitted sender) smtp.mail=judofyr@gmail.com; dkim=pass (test mode) header.i=@gmail.com Received: by bwz23 with SMTP id 23so1849849bwz.1 for ; Tue, 15 Sep 2009 04:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=u2yHAUE8CunkrOeKZrqln3mmDexbMTT0QTOXm8VUJBw=; b=IxLqpDQTpWV1SkcFlCql2nPYgNtuusiR3l1eC445cixIUK2XyeCtuMBC/g1iMHe/Al AAzik4GOqJTnua4ANOVcG0oJf1cHr8K4NkjSamy+/8ZVE2cF2dDj+vrISDWk7nE3Js8w jobrlptRsxo+hKBh9P1VXwQM7kOyE1G5OEofM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=O7+2JYcJ+SoSBg/8PBaSj1CNvyQdVWrwEtx5gXhu8CisBHH9f+RCYZdFlhvS31cwTf rRVgcyjC2R4uJT5POEqN/JrfTCirbmVX1Q+VxDU2ts0S5z9LV7MdPsUmZvoy+ZWk4mQO dwA3NV4QWkL5AvvzegUDytQOqteYQpQn7daJU= MIME-Version: 1.0 Received: by 10.102.204.21 with SMTP id b21mr3244749mug.9.1253015982160; Tue, 15 Sep 2009 04:59:42 -0700 (PDT) In-Reply-To: References: From: Magnus Holm Date: Tue, 15 Sep 2009 13:59:22 +0200 Message-ID: <391a49da0909150459w59c4a41fnd7feeff20107ed4a@mail.gmail.com> Subject: Re: Issue using Ruby1.9 (instance_eval in /lib/rack/builder.rb) 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 Also see http://coderrr.wordpress.com/2009/06/02/fixing-constant-lookup-in-= dsls-in-ruby-1-9/ //Magnus Holm On Tue, Sep 15, 2009 at 13:50, I=C3=B1aki Baz Castillo wrot= e: > > 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 > > =C2=A0 =C2=A0MY_VAR =3D "helloooo" > > =C2=A0 =C2=A0def self.create > =C2=A0 =C2=A0 =C2=A0 =C2=A0Rack::Builder.new do > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0map "/" do > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0puts "[1] MY_VAR = =3D #{MY_VAR}" =C2=A0 <----- [1] =C2=A0(line 20) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0run Proc.new { |en= v| > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0puts= "[2] MY_VAR =3D #{MY_VAR}" =C2=A0 <----- [2] =C2=A0(line 22) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[ 20= 0, {"Content-Type" =3D> "text/plain"}, ["Yeah"] ] > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0end > =C2=A0 =C2=A0 =C2=A0 =C2=A0end > =C2=A0 =C2=A0end > > 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) > =C2=A0 =C2=A0 =C2=A0 =C2=A0from /usr/local/lib/ruby1.9/gems/1.9.1/gems/ra= ck-1.0.0/lib/rack/builder.rb:29:in > `instance_eval' > =C2=A0 =C2=A0 =C2=A0 =C2=A0from /usr/local/lib/ruby1.9/gems/1.9.1/gems/ra= ck-1.0.0/lib/rack/builder.rb:29:in > `initialize' > =C2=A0 =C2=A0 =C2=A0 =C2=A0from /usr/local/lib/ruby1.9/gems/1.9.1/gems/ra= ck-1.0.0/lib/rack/builder.rb:46:in > `new' > =C2=A0 =C2=A0 =C2=A0 =C2=A0from /usr/local/lib/ruby1.9/gems/1.9.1/gems/ra= ck-1.0.0/lib/rack/builder.rb:46:in > `map' > =C2=A0 =C2=A0 =C2=A0 =C2=A0from /root/svn_local_copies/OpenXDMS/trunk/lib= /rack/core.rb:41:in > `block in core' > =C2=A0 =C2=A0 =C2=A0 =C2=A0from /usr/local/lib/ruby1.9/gems/1.9.1/gems/ra= ck-1.0.0/lib/rack/builder.rb:29:in > `instance_eval' > =C2=A0 =C2=A0 =C2=A0 =C2=A0from /usr/local/lib/ruby1.9/gems/1.9.1/gems/ra= ck-1.0.0/lib/rack/builder.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: > > =C2=A0 =C2=A0 =C2=A0 =C2=A0Rack::Builder.new do > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0map "/" do > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0puts "[1] MY_VAR = =3D #{::MyRack::MY_VAR}" =C2=A0 <----- [1] =C2=A0(line 20) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0run Proc.new { |en= v| > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0puts= "[2] MY_VAR =3D #{::MyRack::MY_VAR}" =C2=A0 <----- > [2] =C2=A0(line 22) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[ 20= 0, {"Content-Type" =3D> "text/plain"}, ["Yeah"] ] > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0end > =C2=A0 =C2=A0 =C2=A0 =C2=A0end > > > 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: > > =C2=A0 =C2=A0`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. > > > -- > I=C3=B1aki Baz Castillo > >