@@ 88,9 88,14 @@ class Linker < Parser::TreeRewriter
in [:send, [:gvar, :$: | :$LOAD_PATH], (:<< | :push | :unshift) => m, arg]
loc = arg.location.expression
file = Pathname.new(loc.source_buffer.name)
- path = eval(loc.source, binding, file.to_s, loc.line)
- $LOAD_PATH.public_send(m, Pathname.new(path).relative? ? "#{file.dirname}/#{path}" : path)
- remove(node.location.expression)
+ begin
+ path = eval(loc.source, binding, file.to_s, loc.line)
+ $LOAD_PATH.public_send(m, Pathname.new(path).relative? ? "#{file.dirname}/#{path}" : path)
+ remove(node.location.expression)
+ rescue
+ loc = node.location.expression
+ warn "#{loc}: WARNING: ignoring non-string-literal #{loc.source}"
+ end
in [:send, nil, :require, [:str, arg] => argnode]
path = require(arg)
realpath = Pathname.new(path).realdirpath
@@ 117,8 122,11 @@ class Linker < Parser::TreeRewriter
end
$options[:p] ||= Pathname.new(ARGV[0]).dirname.realdirpath
-$LOAD_PATH.unshift($options[:p])
-$LOAD_PATH.unshift("#{$options[:p]}/lib")
+
+# Use public_send so we can link ourselves, otherwise this global is defined
+# So it will "work" and the lines would be removed in linked output
+$LOAD_PATH.public_send(:unshift, $options[:p])
+$LOAD_PATH.public_send(:unshift, "#{$options[:p]}/lib")
$options[:l].each(&$options[:o].method(:puts)) unless $options[:i]