summaryrefslogtreecommitdiff
path: root/lib/irb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/irb')
-rw-r--r--lib/irb/context.rb4
-rw-r--r--lib/irb/init.rb16
-rw-r--r--lib/irb/input-method.rb2
-rw-r--r--lib/irb/lc/help-message2
4 files changed, 19 insertions, 5 deletions
diff --git a/lib/irb/context.rb b/lib/irb/context.rb
index e6c993d423..b74cae1223 100644
--- a/lib/irb/context.rb
+++ b/lib/irb/context.rb
@@ -115,6 +115,10 @@ module IRB
end
@io = StdioInputMethod.new unless @io
+ when '-'
+ @io = FileInputMethod.new($stdin)
+ @irb_name = '-'
+ @irb_path = '-'
when String
@io = FileInputMethod.new(input_method)
@irb_name = File.basename(input_method)
diff --git a/lib/irb/init.rb b/lib/irb/init.rb
index d2baee2017..d9c4353f39 100644
--- a/lib/irb/init.rb
+++ b/lib/irb/init.rb
@@ -289,6 +289,10 @@ module IRB # :nodoc:
@CONF[:PROMPT_MODE] = prompt_mode
when "--noprompt"
@CONF[:PROMPT_MODE] = :NULL
+ when "--script"
+ noscript = false
+ when "--noscript"
+ noscript = true
when "--inf-ruby-mode"
@CONF[:PROMPT_MODE] = :INF_RUBY
when "--sample-book-mode", "--simple-prompt"
@@ -309,16 +313,20 @@ module IRB # :nodoc:
IRB.print_usage
exit 0
when "--"
- if opt = argv.shift
+ if !noscript && (opt = argv.shift)
@CONF[:SCRIPT] = opt
$0 = opt
end
break
- when /^-/
+ when /^-./
fail UnrecognizedSwitch, opt
else
- @CONF[:SCRIPT] = opt
- $0 = opt
+ if noscript
+ argv.unshift(opt)
+ else
+ @CONF[:SCRIPT] = opt
+ $0 = opt
+ end
break
end
end
diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb
index b77fd3207d..eec2daa549 100644
--- a/lib/irb/input-method.rb
+++ b/lib/irb/input-method.rb
@@ -137,7 +137,7 @@ module IRB
# Creates a new input method object
def initialize(file)
super
- @io = IRB::MagicFile.open(file)
+ @io = file.is_a?(IO) ? file : IRB::MagicFile.open(file)
@external_encoding = @io.external_encoding
end
# The file name of this input method, usually given during initialization.
diff --git a/lib/irb/lc/help-message b/lib/irb/lc/help-message
index 3405fa775f..5b23f4c41e 100644
--- a/lib/irb/lc/help-message
+++ b/lib/irb/lc/help-message
@@ -38,6 +38,8 @@ Usage: irb.rb [options] [programfile] [arguments]
--sample-book-mode, --simple-prompt
Set prompt mode to 'simple'.
--noprompt Don't output prompt.
+ --script Script mode (default, treat first argument as script)
+ --noscript No script mode (leave arguments in argv)
--single-irb Share self with sub-irb.
--tracer Show stack trace for each command.
--back-trace-limit n[=16]