ruby-changes:36627
From: nobu <ko1@a...>
Date: Thu, 4 Dec 2014 08:25:09 +0900 (JST)
Subject: [ruby-changes:36627] nobu:r48708 (trunk): prelude.c.tmpl: require_relative
nobu 2014-12-04 08:25:01 +0900 (Thu, 04 Dec 2014) New Revision: 48708 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48708 Log: prelude.c.tmpl: require_relative * template/prelude.c.tmpl (Prelude#translate): support for require_relative and comments followed by #. Modified files: trunk/template/prelude.c.tmpl Index: template/prelude.c.tmpl =================================================================== --- template/prelude.c.tmpl (revision 48707) +++ template/prelude.c.tmpl (revision 48708) @@ -42,10 +42,14 @@ class Prelude https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L42 result = [@preludes.size, @vpath.strip(filename), lines, sub] @vpath.foreach(filename) do |line| @preludes[filename] ||= result - line.sub!(/(?:^|\s+)\#(?:$|\s.*)/, '') - line.sub!(/require\s*\(?\s*(["'])(.*?)\1\)?/) do - orig, path = $&, $2 - path = translate(path, true) rescue nil + line.sub!(/(?:^|\s+)\#(?:$|[#\s].*)/, '') + line.sub!(/require(_relative)?\s*\(?\s*(["'])(.*?)(?:\.rb)?\2\)?/) do + orig, rel, path = $&, $2, $3 + if rel + path = File.join(File.dirname(filename), path) + nil while path.gsub!(%r'(\A|/)(?!\.\.?/)[^/]+/\.\.(?:/|\z)', '') + end + path = translate("#{path}.rb", true) rescue nil if path @have_sublib = true "TMP_RUBY_PREFIX.require(#{path[0]})" -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/