Sha256: e54649375c72b3c2bdbf049d618208dc4cc4a99fee541db0271dd1467e087734
Contents?: true
Size: 1.38 KB
Versions: 1
Compression:
Stored size: 1.38 KB
Contents
# frozen_string_literal: true require "ruby-next/language/runtime" require "ruby-next/core/runtime" using RubyNext RubyNext::Language::Runtime.watch_dirs << Dir.pwd require "stringio" # Hijack stderr to avoid printing exceptions while executing ruby files stderr = StringIO.new orig_stderr, $stderr = $stderr, stderr # Capture source code passed via `-e` option e_script = nil if $0 == "-e" begin TracePoint.new(:script_compiled) do |tp| next unless tp.path == "-e" e_script = tp.eval_script tp.disable end.enable rescue ArgumentError # script_compiled event is not supported end end at_exit do $stderr = orig_stderr if NoMethodError === $! || SyntaxError === $! if $0 && File.exist?($0) load($0) exit!(0) end if $0 == "-e" && e_script.nil? `ps axw`.split("\n").find { |ps| ps[/\A#{$$}/] }.then do |command| next unless command command.match(/\-e(.*$)/) end.then do |matches| next unless matches args = ["-e", matches[1]] require "optparse" OptionParser.new do |o| o.on("-e SOURCE") do |v| e_script = v end end.parse!(args) end end if e_script new_e_script = RubyNext::Language::Runtime.transform(e_script) TOPLEVEL_BINDING.eval(new_e_script, $0) exit!(0) end end puts(stderr.tap(&:rewind).read) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ruby-next-0.1.0 | lib/uby-next.rb |