Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move body of bin/dietrb into a namespace so not to pollute the toplev…

…el namespace with lvars.
  • Loading branch information...
commit 33b499f34fe32931f3877c9e2eb2d8aebdcd88f6 1 parent 919d02c
@alloy authored
Showing with 49 additions and 42 deletions.
  1. +49 −42 bin/dietrb
View
91 bin/dietrb
@@ -2,48 +2,55 @@
require 'irb'
-unless ARGV.empty?
- require 'optparse'
-
- driver = nil
- ignore_irbrc = false
-
- OptionParser.new do |opt|
- bin = File.basename($0)
- opt.banner = "Usage: #{bin} [options] [programfile] [arguments]"
- opt.on("-f", "Ignore ~/.irbrc") { |i| ignore_irbrc = i }
- opt.on("-r load-lib", "Loads the given library (same as `ruby -r')") { |l| require l }
- opt.on("-d", "Set $DEBUG to true (same as `ruby -d')") { $DEBUG = true }
- opt.on("-I path", "Add path to $LOAD_PATH") { |p| $LOAD_PATH.unshift(p) }
- opt.on("--driver name", "As driver, use one of: tty, readline, or socket") { |d| driver = d }
- opt.on("--noinspect", "Don't use inspect for output") { IRB.formatter.inspect = false }
- opt.on("--simple-prompt", "Simple prompt mode") { IRB.formatter.prompt = :simple }
- opt.on("--noprompt", "No prompt mode") { IRB.formatter.prompt = nil }
- opt.on("-v", "--version", "Print the version of #{bin}") do
- $stdout.puts IRB::VERSION::DESCRIPTION
- exit
- end
- end.parse!(ARGV)
-end
-
-unless ignore_irbrc
- irbrc = File.expand_path("~/.irbrc")
- load(irbrc) if File.exist?(irbrc)
-end
-
-IRB.formatter.filter_from_backtrace << /^#{__FILE__}/
+IRB_CONTEXT_TOPLEVEL_ARGS = [self, TOPLEVEL_BINDING.dup]
-if ARGV.empty?
- driver ||= begin
- require 'readline'
- 'readline'
- rescue LoadError
- 'tty'
+module IRB
+ # Just a namespace so not to pollute the toplevel namespace with lvars.
+ module Bin
+ unless ARGV.empty?
+ require 'optparse'
+
+ driver = nil
+ ignore_irbrc = false
+
+ OptionParser.new do |opt|
+ bin = File.basename($0)
+ opt.banner = "Usage: #{bin} [options] [programfile] [arguments]"
+ opt.on("-f", "Ignore ~/.irbrc") { |i| ignore_irbrc = i }
+ opt.on("-r load-lib", "Loads the given library (same as `ruby -r')") { |l| require l }
+ opt.on("-d", "Set $DEBUG to true (same as `ruby -d')") { $DEBUG = true }
+ opt.on("-I path", "Add path to $LOAD_PATH") { |p| $LOAD_PATH.unshift(p) }
+ opt.on("--driver name", "As driver, use one of: tty, readline, or socket") { |d| driver = d }
+ opt.on("--noinspect", "Don't use inspect for output") { IRB.formatter.inspect = false }
+ opt.on("--simple-prompt", "Simple prompt mode") { IRB.formatter.prompt = :simple }
+ opt.on("--noprompt", "No prompt mode") { IRB.formatter.prompt = nil }
+ opt.on("-v", "--version", "Print the version of #{bin}") do
+ $stdout.puts IRB::VERSION::DESCRIPTION
+ exit
+ end
+ end.parse!(ARGV)
+ end
+
+ unless ignore_irbrc
+ irbrc = File.expand_path("~/.irbrc")
+ load(irbrc) if File.exist?(irbrc)
+ end
+
+ IRB.formatter.filter_from_backtrace << /^#{__FILE__}/
+
+ if ARGV.empty?
+ driver ||= begin
+ require 'readline'
+ 'readline'
+ rescue LoadError
+ 'tty'
+ end
+ require "irb/driver/#{driver}"
+ irb(*IRB_CONTEXT_TOPLEVEL_ARGS)
+ else
+ path = ARGV.shift
+ context = IRB::Context.new(*IRB_CONTEXT_TOPLEVEL_ARGS)
+ File.open(path, 'r') { |f| f.each_line { |line| context.input_line(line) } }
+ end
end
- require "irb/driver/#{driver}"
- irb(self, TOPLEVEL_BINDING.dup)
-else
- path = ARGV.shift
- context = IRB::Context.new(self, TOPLEVEL_BINDING.dup)
- File.open(path, 'r') { |f| f.each_line { |line| context.input_line(line) } }
end
Please sign in to comment.
Something went wrong with that request. Please try again.