From: "Iñaki Baz Castillo" <ibc@aliax.net>
To: rack-devel@googlegroups.com
Subject: Issue using Ruby1.9 (instance_eval in /lib/rack/builder.rb)
Date: Tue, 15 Sep 2009 13:50:56 +0200 [thread overview]
Message-ID: <cc1f582e0909150450k3a52cb17g146f4ca89cf9b80@mail.gmail.com> (raw)
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 = "helloooo"
def self.create
Rack::Builder.new do
map "/" do
puts "[1] MY_VAR = #{MY_VAR}" <----- [1] (line 20)
run Proc.new { |env|
puts "[2] MY_VAR = #{MY_VAR}" <----- [2] (line 22)
[ 200, {"Content-Type" => "text/plain"}, ["Yeah"] ]
}
end
end
end
end
rack_core = 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/builder.rb:29:in
`instance_eval'
from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.rb:29:in
`initialize'
from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.rb:46:in
`new'
from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.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/builder.rb:29:in
`instance_eval'
from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-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:
Rack::Builder.new do
map "/" do
puts "[1] MY_VAR = #{::MyRack::MY_VAR}" <----- [1] (line 20)
run Proc.new { |env|
puts "[2] MY_VAR = #{::MyRack::MY_VAR}" <-----
[2] (line 22)
[ 200, {"Content-Type" => "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.
--
Iñaki Baz Castillo
<ibc@aliax.net>
next reply other threads:[~2009-09-15 11:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-15 11:50 Iñaki Baz Castillo [this message]
2009-09-15 11:59 ` Issue using Ruby1.9 (instance_eval in /lib/rack/builder.rb) Magnus Holm
2009-09-15 12:46 ` Iñaki Baz Castillo
2009-09-15 16:03 ` Yehuda Katz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://groups.google.com/group/rack-devel
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cc1f582e0909150450k3a52cb17g146f4ca89cf9b80@mail.gmail.com \
--to=rack-devel@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).