byrnejb
2010-Sep-09 16:25 UTC
1.9.2 why does relative_require need an additional backtrack in path
Why does Ruby-1.9.2-p0 require an additional ../ for relative paths when compared to the same code for ruby1.8? if RUBY_VERSION < ''1.9'' require File.dirname(__FILE__) + library else require_relative File.dirname(__FILE__) + ''/..'' + library end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Yehuda Katz
2010-Sep-09 17:35 UTC
Re: 1.9.2 why does relative_require need an additional backtrack in path
You''re passing an absolute path to require_relative. You can do require_relative library. That said, in my opinion, require_relative is a misfeature. You should always put the appropriate paths on the load path, and require things relative to it. If your library is called "zoom", you should do require "zoom/library_name", not require File.dirname(__FILE__) + "library_name" from the zoom directory. Yehuda Katz Architect | Engine Yard (ph) 718.877.1325 On Thu, Sep 9, 2010 at 9:25 AM, byrnejb <byrnejb@harte-lyne.ca> wrote:> Why does Ruby-1.9.2-p0 require an additional ../ for relative paths > when compared to the same code for ruby1.8? > > if RUBY_VERSION < ''1.9'' > require File.dirname(__FILE__) + library > else > require_relative File.dirname(__FILE__) + ''/..'' + library > end > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
byrnejb
2010-Sep-09 21:05 UTC
Re: 1.9.2 why does relative_require need an additional backtrack in path
On Sep 9, 1:35 pm, Yehuda Katz <wyc...@gmail.com> wrote:> You''re passing an absolute path to require_relative. You can do > require_relative library.The path that gets sent to relative_root has this value: bin/../../lib/forex/hll_forex_ca_feed That does not appear to me to be an absolute path.> > That said, in my opinion, require_relative is a misfeature. You should > always put the appropriate paths on the load path, and require things > relative to it. If your library is called "zoom", you should do require > "zoom/library_name", not require File.dirname(__FILE__) + "library_name" > from the zoom directory. >I would very much prefer that Ruby-1.9.2 retained the cwd (.) in the load path and then all of this jiggery-pokery with require_relative would not be necessary at all. However that may be. When I run this code in 1.8.7 under Rails-2.3.8 the script runs without error and produces the expected output. With 1.9.2 and Rails-2.3.8 it also runs without error, albeit requires the additional ../. I just do not understand why the additional ../ is required for 1.9.2 require_relative. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
byrnejb
2010-Sep-11 00:04 UTC
Re: 1.9.2 why does relative_require need an additional backtrack in path
On Sep 9, 5:05 pm, byrnejb <byrn...@harte-lyne.ca> wrote:> On Sep 9, 1:35 pm, Yehuda Katz <wyc...@gmail.com> wrote: > > > You''re passing an absolute path to require_relative. You can do > > require_relative library. > > The path that gets sent to relative_root has this value: > > bin/../../lib/forex/hll_forex_ca_feed > > That does not appear to me to be an absolute path.Taking your hint I ended up with this construct, which appears to serve both 1.8 and 1.9 rubies. require File.expand_path(File.dirname(__FILE__) + library) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Apparently Analagous Threads
- Using require_relative to speed up rspec require time.
- Problem Installing Latest WINE in Backtrack 4
- [LLVMdev] [PATCH] utils/unittest: Consistency of gtest and gtest_main libs.
- Understanding the version handling in LLVM/Clang/LLD
- (Rails3-master) erubis: how to use things like preprocessing?