Code Monkey home page Code Monkey logo

irb's Introduction

IRB

Gem Version build

IRB stands for "interactive Ruby" and is a tool to interactively execute Ruby expressions read from the standard input.

The irb command from your shell will start the interpreter.

Installation

Note

IRB is a default gem of Ruby so you shouldn't need to install it separately.

But if you're using Ruby 2.6 or later and want to upgrade/install a specific version of IRB, please follow these steps.

To install it with bundler, add this line to your application's Gemfile:

gem 'irb'

And then execute:

$ bundle

Or install it directly with:

$ gem install irb

Usage

Note

We're working hard to match Pry's variety of powerful features in IRB, and you can track our progress or find contribution ideas in this document.

The irb Executable

You can start a fresh IRB session by typing irb in your terminal.

In the session, you can evaluate Ruby expressions or even prototype a small Ruby script. An input is executed when it is syntactically complete.

$ irb
irb(main):001> 1 + 2
=> 3
irb(main):002* class Foo
irb(main):003*   def foo
irb(main):004*     puts 1
irb(main):005*   end
irb(main):006> end
=> :foo
irb(main):007> Foo.new.foo
1
=> nil

The binding.irb Breakpoint

If you use Ruby 2.5 or later versions, you can also use binding.irb in your program as breakpoints.

Once a binding.irb is evaluated, a new IRB session will be started with the surrounding context:

$ ruby test.rb

From: test.rb @ line 2 :

    1: def greet(word)
 => 2:   binding.irb
    3:   puts "Hello #{word}"
    4: end
    5:
    6: greet("World")

irb(main):001:0> word
=> "World"
irb(main):002:0> exit
Hello World

Commands

The following commands are available on IRB. You can get the same output from the help command.

Help
  help           List all available commands. Use `help <command>` to get information about a specific command.

IRB
  exit           Exit the current irb session.
  exit!          Exit the current process.
  irb_load       Load a Ruby file.
  irb_require    Require a Ruby file.
  source         Loads a given file in the current session.
  irb_info       Show information about IRB.
  history        Shows the input history. `-g [query]` or `-G [query]` allows you to filter the output.

Workspace
  cwws           Show the current workspace.
  chws           Change the current workspace to an object.
  workspaces     Show workspaces.
  pushws         Push an object to the workspace stack.
  popws          Pop a workspace from the workspace stack.

Multi-irb (DEPRECATED)
  irb            Start a child IRB.
  jobs           List of current sessions.
  fg             Switches to the session of the given number.
  kill           Kills the session with the given number.

Debugging
  debug          Start the debugger of debug.gem.
  break          Start the debugger of debug.gem and run its `break` command.
  catch          Start the debugger of debug.gem and run its `catch` command.
  next           Start the debugger of debug.gem and run its `next` command.
  delete         Start the debugger of debug.gem and run its `delete` command.
  step           Start the debugger of debug.gem and run its `step` command.
  continue       Start the debugger of debug.gem and run its `continue` command.
  finish         Start the debugger of debug.gem and run its `finish` command.
  backtrace      Start the debugger of debug.gem and run its `backtrace` command.
  info           Start the debugger of debug.gem and run its `info` command.

Misc
  edit           Open a file or source location.
  measure        `measure` enables the mode to measure processing time. `measure :off` disables it.

Context
  show_doc       Enter the mode to look up RI documents.
  ls             Show methods, constants, and variables.
  show_source    Show the source code of a given method or constant.
  whereami       Show the source code around binding.irb again.

Aliases
  $              Alias for `show_source`
  @              Alias for `whereami`

Debugging with IRB

Starting from version 1.8.0, IRB boasts a powerful integration with debug.gem, providing a debugging experience akin to pry-byebug.

After hitting a binding.irb breakpoint, you can activate the debugger with the debug command. Alternatively, if the debug method happens to already be defined in the current scope, you can call irb_debug.

From: test.rb @ line 3 :

    1:
    2: def greet(word)
 => 3:   binding.irb
    4:   puts "Hello #{word}"
    5: end
    6:
    7: greet("World")

irb(main):001> debug
irb:rdbg(main):002>

Once activated, the prompt's header changes from irb to irb:rdbg, enabling you to use any of debug.gem's commands:

irb:rdbg(main):002> info # use info command to see available variables
%self = main
_ = nil
word = "World"
irb:rdbg(main):003> next # use next command to move to the next line
[1, 7] in test.rb
     1|
     2| def greet(word)
     3|   binding.irb
=>   4|   puts "Hello #{word}"
     5| end
     6|
     7| greet("World")
=>#0    Object#greet(word="World") at test.rb:4
  #1    <main> at test.rb:7
irb:rdbg(main):004>

Simultaneously, you maintain access to IRB's commands, such as show_source:

irb:rdbg(main):004> show_source greet

From: test.rb:2

def greet(word)
  binding.irb
  puts "Hello #{word}"
end

More about debug.gem

debug.gem offers many advanced debugging features that simple REPLs can't provide, including:

  • Step-debugging
  • Frame navigation
  • Setting breakpoints with commands
  • Thread control
  • ...and many more

To learn about these features, please refer to debug.gem's commands list.

In the irb:rdbg session, the help command will also display all commands from debug.gem.

Advantages Over debug.gem's Console

This integration offers several benefits over debug.gem's native console:

  1. Access to handy IRB commands like show_source or show_doc.
  2. Support for multi-line input.
  3. Symbol shortcuts such as @ (whereami) and $ (show_source).
  4. Autocompletion.
  5. Customizable prompt.

However, there are also some limitations to be aware of:

  1. binding.irb doesn't support pre and do arguments like binding.break.
  2. As IRB doesn't currently support remote-connection, it can't be used with debug.gem's remote debugging feature.
  3. Access to the previous return value via the underscore _ is not supported.

Type Based Completion

IRB's default completion IRB::RegexpCompletor uses Regexp. IRB has another experimental completion IRB::TypeCompletor that uses type analysis.

How to Enable IRB::TypeCompletor

Install ruby/repl_type_completor with:

$ gem install repl_type_completor

Or add these lines to your project's Gemfile.

gem 'irb'
gem 'repl_type_completor', group: [:development, :test]

Now you can use type based completion by:

Running IRB with the --type-completor option

$ irb --type-completor

Or writing this line to IRB's rc-file (e.g. ~/.irbrc)

IRB.conf[:COMPLETOR] = :type # default is :regexp

Or setting the environment variable IRB_COMPLETOR

ENV['IRB_COMPLETOR'] = 'type'
IRB.start

To check if it's enabled, type irb_info into IRB and see the Completion section.

irb(main):001> irb_info
...
# Enabled
Completion: Autocomplete, ReplTypeCompletor: 0.1.0, Prism: 0.18.0, RBS: 3.3.0
# Not enabled
Completion: Autocomplete, RegexpCompletor
...

If you have sig/ directory or rbs_collection.lock.yaml in current directory, IRB will load it.

Advantage over Default IRB::RegexpCompletor

IRB::TypeCompletor can autocomplete chained methods, block parameters and more if type information is available. These are some examples IRB::RegexpCompletor cannot complete.

irb(main):001> 'Ruby'.upcase.chars.s # Array methods (sample, select, shift, size)
irb(main):001> 10.times.map(&:to_s).each do |s|
irb(main):002>   s.up # String methods (upcase, upcase!, upto)
irb(main):001> class User < ApplicationRecord
irb(main):002>   def foo
irb(main):003>     sa # save, save!

As a trade-off, completion calculation takes more time than IRB::RegexpCompletor.

Difference between Steep's Completion

Compared with Steep, IRB::TypeCompletor has some difference and limitations.

[0, 'a'].sample.
# Steep completes intersection of Integer methods and String methods
# IRB::TypeCompletor completes both Integer and String methods

Some features like type narrowing is not implemented.

def f(arg = [0, 'a'].sample)
  if arg.is_a?(String)
    arg. # Completes both Integer and String methods

Unlike other static type checker, IRB::TypeCompletor uses runtime information to provide better completion.

irb(main):001> a = [1]
=> [1]
irb(main):002> a.first. # Completes Integer methods

Configuration

Environment Variables

  • NO_COLOR: Assigning a value to it disables IRB's colorization.
  • IRB_USE_AUTOCOMPLETE: Setting it to false disables IRB's autocompletion.
  • IRB_COMPLETOR: Configures IRB's auto-completion behavior, allowing settings for either regexp or type.
  • VISUAL: Its value would be used to open files by the edit command.
  • EDITOR: Its value would be used to open files by the edit command if VISUAL is unset.
  • IRBRC: The file specified would be evaluated as IRB's rc-file.

Documentation

https://ruby.github.io/irb/

Extending IRB

IRB v1.13.0 and later versions allows users/libraries to extend its functionality through official APIs.

For more information, please visit EXTEND_IRB.md.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/irb.

Set up the environment

  1. Fork the project to your GithHub account
  2. Clone the fork with git clone [email protected]:[your_username]/irb.git
  3. Run bundle install
  4. Run bundle exec rake to make sure tests pass locally

Run integration tests

If your changes affect component rendering, such as the autocompletion's dialog/dropdown, you may need to run IRB's integration tests, known as yamatanooroti.

Before running these tests, ensure that you have libvterm installed. If you're using Homebrew, you can install it by running:

brew install libvterm

After installing libvterm, you can run the integration tests using the following commands:

WITH_VTERM=1 bundle install
WITH_VTERM=1 bundle exec rake test test_yamatanooroti

Releasing

rake release
gh release create vX.Y.Z --generate-notes

License

The gem is available as open source under the terms of the 2-Clause BSD License.

irb's People

Contributors

akr avatar amatsuda avatar aycabta avatar burdettelamar avatar colby-swandale avatar dependabot[bot] avatar drbrain avatar eregon avatar hogelog avatar hsbt avatar ima1zumi avatar jeremyevans avatar k0kubun avatar kaiquekandykoga avatar knu avatar ko1 avatar mame avatar marcandre avatar no6v avatar nobu avatar nurse avatar osyo-manga avatar peterzhu2118 avatar pocke avatar st0012 avatar stomar avatar tompng avatar ydah avatar yugui avatar znz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

irb's Issues

Ctrl-C stops working after using binding.irb

When using binding.irb, subsequent use of SIGINT fails.

current = Signal.trap(:INT) {puts "Handled"}

Process.kill(:INT, Process.pid)

binding.irb

Process.kill(:INT, Process.pid)

Gives:

Handled

From: /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/320667e1-6291-4143-979c-a113e661d440 @ line 5 :

    1: current = Signal.trap(:INT) {puts "Handled"}
    2: 
    3: Process.kill(:INT, Process.pid)
    4: 
 => 5: binding.irb
    6: 
    7: Process.kill(:INT, Process.pid)
    8: 

irb(main):001:0> ^D

Using the following code:

binding.irb

current = Signal.trap(:INT) {puts "Handled"}

puts current.inspect

...we can see the signal is not restored:

From: /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/fe62f3b3-200b-4bbb-926d-c6686dad1d93 @ line 1 :

 => 1: binding.irb
    2: 
    3: current = Signal.trap(:INT) {puts "Handled"}
    4: 
    5: puts current.inspect
irb(main):001:0> 
#<Proc:0x00007fb8648481d0 /Users/samuel/.rubies/ruby-2.7.1/lib/ruby/2.7.0/irb.rb:465>

irb exit with C-d in sub-irb

ruby 2.6.5's irb returns to main irb.

% ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]
% ruby -e 'puts "irb"; puts "\cd"; puts ":dummy"' | irb
Switch to inspect mode.
irb
Switch to inspect mode.

#<IRB::Irb: @context=#<IRB::Context:0x00007fa2c0110070>, @signal_status=:IN_EVAL, @scanner=#<RubyLex:0x00007fa2bd82c2a8>>

nil
:dummy
:dummy

% irb
irb(main):001:0> irb
irb#1(main):001:0> `C-d`
=> #<IRB::Irb: @context=#<IRB::Context:0x00007fdfbc2a8020>, @signal_status=:IN_EVAL, @scanner=#<RubyLex:0x00007fdfbc02cb70>>
irb(main):002:0> `C-d`

But 2.7.0-preview2's irb exits.

% rbenv shell 2.7.0-preview2
% ruby -v
ruby 2.7.0preview2 (2019-10-22 master 02aadf1032) [x86_64-darwin18]
% ruby -e 'puts "irb"; puts "\cd"; puts ":dummy"' | irb
Switch to inspect mode.
irb
Switch to inspect mode.

#<IRB::Irb: @context=#<IRB::Context:0x00007fc2d8835c00>, @signal_status=:IN_EVAL, @scanner=#<RubyLex:0x00007fc2d8903268>>

:dummy

nil
% irb
irb(main):001:0> irb
irb#1(main):001:0> `C-d`
=> #<IRB::Irb: @context=#<IRB::Context:0x00007fd47016eb20>, @signal_status=:IN_EVAL, @scanner=#<RubyLex:0x00007fd471095d10>>

Non-ASCII input Support

My issue might be platform-specific (I’m using Windows 10).

  • Windows Terminal: Inputting a non-ASCII character softlocks IRB / the terminal emulator (not even ctrl+c does anything).
  • cmd.exe and powershell: Inputting a non-ASCII character crashes either terminal emulator.
    All three support non-ASCII insertion outside IRB, so I believe this is an IRB bug.

Note that Windows Terminal is the only terminal emulator I know that this issue persisted (the other two I only tested for reporting this issue).

No impact on USA Rubyists, of course. I only noted this issue after installing a new keyboard layout, and it has occurred to me ever since whenever I forgot to change my keyboard layout.

Methods defined in default context have public visibility

$ irb --version
irb 1.1.0.pre.3 (2019-09-01)
$ irb
irb(main):001:1* def hello
irb(main):002:1*   "Hello, #{self}!"
irb(main):003:0> end
=> :hello
irb(main):004:0> "world".hello
=> "Hello, world!"

It seems that Module#private here has stopped working since Ruby 2.3.

With --context-mode 0, methods are private as expected.

$ irb --context-mode 0
irb(main):001:1* def hello
irb(main):002:1*   "Hello, #{self}!"
irb(main):003:0> end
=> :hello
irb(main):004:0> "world".hello
Traceback (most recent call last):
  (omit)
NoMethodError (private method `hello' called for "world":String)
irb(main):005:0> public
=> Object
irb(main):006:1* def hello2
irb(main):007:1*   "Hello, #{self}!"
irb(main):008:0> end
=> :hello2
irb(main):009:0> "world".hello2
=> "Hello, world!"

Related topics:

IRB 2.7.0 crush: undefined method `[]' for nil:NilClass (NoMethodError)

Hi, everyone!

I've found some unexpected behavior of IRB 2.7. If you enter the following code to the REPL you will get next backtrace:

2.7.0 :001 > class Symbol
2.7.0 :002 >   def to_proc(*args)
2.7.0 :003 >     proc {}
2.7.0 :004 >   end
2.7.0 :005 > end
 => :to_proc
Traceback (most recent call last):
	29: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/bin/irb:23:in `<main>'
	28: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/bin/irb:23:in `load'
	27: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/gems/irb-1.2.1/exe/irb:11:in `<top (required)>'
	26: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:398:in `start'
	25: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:469:in `run'
	24: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:469:in `catch'
	23: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:470:in `block in run'
	22: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:535:in `eval_input'
	21: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:134:in `each_top_level_statement'
	20: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:134:in `catch'
	19: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:135:in `block in each_top_level_statement'
	18: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:135:in `loop'
	17: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:138:in `block (2 levels) in each_top_level_statement'
	16: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:166:in `lex'
	15: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:516:in `block in eval_input'
	14: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:693:in `signal_status'
	13: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:517:in `block (2 levels) in eval_input'
	12: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/input-method.rb:258:in `gets'
	11: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/forwardable.rb:235:in `readmultiline'
	10: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/forwardable.rb:235:in `readmultiline'
	 9: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:170:in `readmultiline'
	 8: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:221:in `inner_readline'
	 7: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:330:in `rerender'
	 6: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:77:in `check_multiline_prompt'
	 5: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:50:in `block in set_input'
	 4: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:50:in `each_index'
	 3: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:52:in `block (2 levels) in set_input'
	 2: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:110:in `check_state'
	 1: from /Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:456:in `process_literal_type'
/Users/woarewe/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:424:in `check_string_literal': undefined method `[]' for nil:NilClass (NoMethodError)

Thanks for your attention.

Crash with Hash with non-UTF8 key

Description

Expected

Raise EncodingError (and shown by irb), but irb doesn't stop

Actual

When I tried to input {"device \xAE": 1},

$ RUBYOPT=-v irb
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]
irb(main)[01:0]> IRB::VERSION
=> "1.2.1"
irb(main)[02:1]* {"device \xAE": Traceback (most recent call last):
        37: from /Users/k0kubun/.rbenv/versions/2.7.0/bin/irb:23:in `<main>'
        36: from /Users/k0kubun/.rbenv/versions/2.7.0/bin/irb:23:in `load'
        35: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/irb-1.2.1/exe/irb:11:in `<top (required)>'
        34: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:398:in `start'
        33: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:469:in `run'
        32: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:469:in `catch'
        31: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:470:in `block in run'
        30: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:535:in `eval_input'
        29: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:134:in `each_top_level_statement'
        28: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:134:in `catch'
        27: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:135:in `block in each_top_level_statement'
        26: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:135:in `loop'
        25: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:138:in `block (2 levels) in each_top_level_statement'
        24: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:166:in `lex'
        23: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:516:in `block in eval_input'
        22: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:693:in `signal_status'
        21: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:517:in `block (2 levels) in eval_input'
        20: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/input-method.rb:258:in `gets'
        19: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/forwardable.rb:235:in `readmultiline'
        18: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/forwardable.rb:235:in `readmultiline'
        17: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:170:in `readmultiline'
        16: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:232:in `inner_readline'
        15: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:232:in `loop'
        14: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:233:in `block in inner_readline'
        13: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:262:in `read_io'
        12: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:262:in `loop'
        11: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:303:in `block in read_io'
        10: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:234:in `block (2 levels) in inner_readline'
         9: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:234:in `each'
         8: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:236:in `block (3 levels) in inner_readline'
         7: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:330:in `rerender'
         6: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:77:in `check_multiline_prompt'
         5: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:50:in `block in set_input'
         4: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:50:in `each_index'
         3: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:52:in `block (2 levels) in set_input'
         2: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:113:in `check_state'
         1: from /Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:212:in `check_code_block'
/Users/k0kubun/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:212:in `compile': invalid symbol in encoding UTF-8 :"device \\xAE" (EncodingError)

Terminal Emulator

macOS Terminal.app

irb does not print result for assignments

Expected behavior: When an assignment expression is entered, irb prints its value.
Actual behavior: Nothing is printed.

% ruby -v
ruby 2.7.0dev (2019-11-07T14:33:45Z master d62abc47c8) [x86_64-linux]
% bundle exec exe/irb -f
irb(main):001:0> a=1
irb(main):002:0>

% ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
% irb -f
irb(main):001:0> a=1
=> 1
irb(main):002:0>

IRB 1.2.0 broken on a Heroku private space

$ heroku run bash -a schneems-my-space-app --size=private-s
~ $ bundle exec irb -v
irb 1.2.0 (2019-12-07)
~ $ bundle exec irb
This version of IRB is drastically different from the previous version.
If you hit any issues, you can use "irb --legacy" to run the old version.
If you want to just erase this message, please use "irb --multiline" or
add `IRB.conf[:USE_MULTILINE] = true` to your ~/.irbrc file.
bundler: failed to load command: irb (/app/vendor/bundle/ruby/2.5.0/bin/irb)
ZeroDivisionError: divided by 0
  /app/vendor/bundle/ruby/2.5.0/gems/reline-0.0.7/lib/reline/line_editor.rb:208:in `div'
  /app/vendor/bundle/ruby/2.5.0/gems/reline-0.0.7/lib/reline/line_editor.rb:208:in `calculate_height_by_width'
  /app/vendor/bundle/ruby/2.5.0/gems/reline-0.0.7/lib/reline/line_editor.rb:349:in `rerender'
  /app/vendor/bundle/ruby/2.5.0/gems/reline-0.0.7/lib/reline.rb:210:in `inner_readline'
  /app/vendor/bundle/ruby/2.5.0/gems/reline-0.0.7/lib/reline.rb:160:in `readmultiline'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb/input-method.rb:258:in `gets'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb.rb:517:in `block (2 levels) in eval_input'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb.rb:693:in `signal_status'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb.rb:516:in `block in eval_input'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb/ruby-lex.rb:166:in `lex'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb/ruby-lex.rb:138:in `block (2 levels) in each_top_level_statement'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb/ruby-lex.rb:135:in `loop'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb/ruby-lex.rb:135:in `block in each_top_level_statement'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb/ruby-lex.rb:134:in `catch'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb/ruby-lex.rb:134:in `each_top_level_statement'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb.rb:535:in `eval_input'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb.rb:470:in `block in run'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb.rb:469:in `catch'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb.rb:469:in `run'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/lib/irb.rb:398:in `start'
  /app/vendor/bundle/ruby/2.5.0/gems/irb-1.2.0/exe/irb:11:in `<top (required)>'
  /app/vendor/bundle/ruby/2.5.0/bin/irb:23:in `load'
  /app/vendor/bundle/ruby/2.5.0/bin/irb:23:in `<top (required)>'
~ $ ~ $ ~ $ ~ $ ~ $ ~ $ ~ $ ~ $ ~ $ ~ $ ~ $

You can email me [email protected] and I can give a collaborator access to the app for debugging.

If you run it with irb --legacy it works fine.

Internal ticket for Heroku ID 800955

Ctrl-Y (yank) no longer works after statement entry

Description

After killing a line (or part of a line) with Ctrl-K, it is normally retained and can be recalled with Ctrl-Y. Since Ruby 2.7.0, the kill buffer is cleared after a command is entered and Ctrl-Y does nothing.

Note that this only happens when a complete statement is entered (whether syntactically valid or not). When editing or adding to a multiline expression (such as a block or conditional body) the kill buffer is retained until either replaced or the entire statement is evaluated (or rejected with a SyntaxError).

Steps to reproduce

  1. Type any statement, such as a = 5, but don't press enter
  2. Press Ctrl-A to go to the head of the line, then Ctrl-K to kill the entire line
  3. Type any statement and press enter, or just press enter on the blank line
  4. Press Ctrl-Y

Expected result

a = 5 is placed on the command line.

Actual result

Nothing happens.

Terminal Emulator

iTerm2 MacOS

Please include irb(1) man page in gem

Recently irb(1) man page was added to this repository. But it is not included in gem of 1.1.0.pre.3. Please consider including it in that of 1.1.0 release.

An example of gem that includes man pages are bundler. Hope this helps.

too many .irb_history files in different directories

The irb included with

$ ruby -v
ruby 2.7.0dev (2019-10-24) [x86_64-openbsd6.6]

always saves .irb_history in the current directory. Because of this, I now have many invisible .irb_history files in different directories. If I can't write /etc/.irb_history (for example), I get an error when exiting irb:

pehcehwahn$ cd /etc
pehcehwahn$ irb
irb(main):001:0> exit
Traceback (most recent call last):
        10: from /home/kernigh/prefix/bin/irb:23:in `<main>'
         9: from /home/kernigh/prefix/bin/irb:23:in `load'
         8: from /home/kernigh/prefix/lib/ruby/gems/2.7.0/gems/irb-1.1.0.pre.3/exe/irb:11:in `<top (required)>'
         7: from /home/kernigh/prefix/lib/ruby/2.7.0/irb.rb:389:in `start'
         6: from /home/kernigh/prefix/lib/ruby/2.7.0/irb.rb:464:in `run'
         5: from /home/kernigh/prefix/lib/ruby/2.7.0/irb.rb:464:in `each'
         4: from /home/kernigh/prefix/lib/ruby/2.7.0/irb.rb:464:in `block in run'
         3: from /home/kernigh/prefix/lib/ruby/2.7.0/irb/ext/save-history.rb:62:in `block in extended'
         2: from /home/kernigh/prefix/lib/ruby/2.7.0/irb/ext/save-history.rb:110:in `save_history'
         1: from /home/kernigh/prefix/lib/ruby/2.7.0/irb/ext/save-history.rb:110:in `open'
/home/kernigh/prefix/lib/ruby/2.7.0/irb/ext/save-history.rb:110:in `initialize': Permission denied @ rb_sysopen - /etc/.irb_history (Errno::EACCES)

The problem seems to be in lib/init.rb IRB.rc_file_generators:

  # enumerate possible rc-file base name generators
  def IRB.rc_file_generators
    if irbrc = ENV["IRBRC"]
      yield proc{|rc| rc == "rc" ? irbrc : irbrc+rc}
    end
    if home = ENV["HOME"]
      yield proc{|rc| home+"/.irb#{rc}"}  # <---- line 275
    end
    home = Dir.pwd
    yield proc{|rc| home+"/.irb#{rc}"}
    yield proc{|rc| home+"/irb#{rc.sub(/\A_?/, '.')}"}
    yield proc{|rc| home+"/_irb#{rc}"}
    yield proc{|rc| home+"/$irb#{rc}"}
  end

IRB set IRB.conf[:RC_NAME_GENERATOR] to the proc on line 275 (which I marked above), but then it did home = Dir.pwd, so it would put .irb_history in the current directory, not my home directory.

irb(main):002:0> IRB.conf[:RC_NAME_GENERATOR]
=> #<Proc:0x00000e48eac62280 /home/kernigh/prefix/lib/ruby/2.7.0/irb/init.rb:275>
irb(main):003:0> IRB.conf[:RC_NAME_GENERATOR].binding.eval("home")
=> "/etc"
irb(main):004:0> IRB.conf[:RC_NAME_GENERATOR].("_history")
=> "/etc/.irb_history"
irb(main):005:0> ENV["HOME"]
=> "/home/kernigh"
irb(main):006:0> ENV["IRBRC"]
=> nil

Make `literal_type` indicator detect more open chunks of code, not only strings

Description

Literal type (or @ltype) is this character in the end of prompt:

          ↓
2.6.3 :001 > 'closed string'
2.6.3 :002"> %Q[not closed array of words
2.6.3 :003/> /not closed regexp
2.6.3 :004`> `echo open backtick
          ↑

Documentation says that it detects string types:

#     %l    # type of string(", ', /, ]), `]' is inner %w[...]

But it already does more than that, detecting regular expressions and some array types:

2.6.3 :003/> /not closed regexp
# Array of words
2.6.3 :003]> %w[word word

So I think it would be convenient if it detected open parentheses, square and curly braces as well. For example:

2.6.3 :003)> parentheses = (a + b * c
2.6.3 :003]> array = [1, 'milk'

Having a leading uppercase Unicode letter in the name of a class causes an error

Details
If you run one of the following examples (I'm using irb 1.0.0 (2018-12-18)) in console:

  • class Класс + Enter
  • class Σφάλμα + Enter
  • class ЖClass + Enter

you'll get a SyntaxError like this:

SyntaxError ((irb):1: syntax error, unexpected end-of-input, expecting end)

So the first Unicode symbol causes this kind of error.
At the same time code like this works fine: class Класс; end.

What is expected to be

Basically it should run like any similar piece of code:

2.6.0 :001 > class Kласс
2.6.0 :002?>   # ... 
2.6.0 :003?> end

RDoc for predicate methods

I noticed that RDoc for predicate methods (i.e. end with ?) are not shown.
I guess the root cause is that ? is escaped.

IRB::InputCompletor.retrieve_completion_data("1.odd?", bind: binding, doc_namespace: true)
# => "Integer.odd\\?"

Recalling command history no longer works in 2.7.0

Prior to 2.7.0 the default version of irb allowed you to recall command history by pressing the up arrow. Now this seems to be disabled, weirdly it seems to be saving command history, just not allowing recall. If I switch to irb --legacy the recall is enabled and I can press "up" to recall commands entered in previous sessions without the --legacy flag.

Ruby: 2.7.0
IRB: 1.2.1 (2019-12-24)
OS: Mac OS Catalina
Terminal: iTerm2 Build 3.3.10

`def foo(&nil);end` does not raise syntax error

Expected: raise syntax error like ruby command

% ruby -e 'def foo(&nil); end'
-e:1: syntax error, unexpected `nil', expecting local variable or method
def foo(&nil); end

Actual: continue to input with indents

irb(main):001:1> def foo(&nil); end
irb(main):002:1>   end
irb(main):003:1>     end
irb(main):004:1>

IRB runs out of memory when inspecting lots of data

Description

This happened in the context of printing ~50000 large ActiveRecord objects (45 attributes) in a Rails 5.1 App, but here's a reproducer with plain Ruby:

'abc' * 20_000_000

Executing that in IRB results in this traceback on my machine:

Traceback (most recent call last):
   16: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb.rb:399:in `start'
   15: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb.rb:470:in `run'
   14: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb.rb:470:in `catch'
   13: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb.rb:471:in `block in run'
   12: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb.rb:536:in `eval_input'
   11: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb/ruby-lex.rb:134:in `each_top_level_statement'
   10: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb/ruby-lex.rb:134:in `catch'
    9: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb/ruby-lex.rb:135:in `block in each_top_level_statement'
    8: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb/ruby-lex.rb:135:in `loop'
    7: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb/ruby-lex.rb:150:in `block (2 levels) in each_top_level_statement'
    6: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb.rb:537:in `block in eval_input'
    5: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb.rb:694:in `signal_status'
    4: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb.rb:541:in `block (2 levels) in eval_input'
    3: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb.rb:741:in `output_value'
    2: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb.rb:741:in `!~'
    1: from /home/<user>/.gem/ruby/2.6.5/gems/irb-1.2.3/lib/irb.rb:741:in `=~'
RegexpError (failed to allocate memory: /\A.*\Z/)

This works fine in pry and might be because I'm using irb 1.2.3 with Ruby 2.6.5, instead of Ruby 2.7.

Terminal Emulator

URVXT

Other system info

Memory: 16GB
OS: Xubuntu 18.04

Let me know if you need any more information.

irb fails to start, cannot load "easter-egg"

Description

Expected: irb starts

Actual: irb
Traceback (most recent call last):
7: from /usr/local/bin/irb:23:in <main>' 6: from /usr/local/bin/irb:23:in load'
5: from /usr/local/lib/ruby/gems/2.6.0/gems/irb-1.2.2/exe/irb:9:in <top (required)>' 4: from /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require'
3: from /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require' 2: from /usr/local/lib/ruby/gems/2.6.0/gems/irb-1.2.2/lib/irb.rb:24:in <top (required)>'
1: from /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require' /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require': cannot load such file -- irb/easter-egg (LoadError)

Terminal Emulator

xterm

Platform

CentOS 7, patched
Ruby: ruby 2.6.6p124 (2019-12-18 revision 67836) [x86_64-linux]
Updated OS and Gems this morning. irb worked before the updates.
Mostly worked, the update a week or so ago broke readline. Fixed by copying in readline.so from /usr/local/lib/ruby/2.7.0 to 2.6.0

Cannot paste in 53 lines

When I try pasting in this code, it is extremely slow on my machine and stops around line 37:

require 'thread'

def fib( n )
  return  n  if ( 0..1 ).include? n
  ( fib( n - 1 ) + fib( n - 2 ) )
end

thread_execution_time = Hash.new {|h, k| h[k] = [] }
mutex = Mutex.new
cv = ConditionVariable.new

execution_time = []
thread_count = 1
work_count = 512

(1..128).each do |thread_count|
  sequential_work = Array.new(work_count, 20)
  mutex.lock
  threads = []
  thread_count.times.each do
    threads << Thread.new do
      begin
        loop do
          mutex.synchronize do
            #cv.wait(mutex)
            if sequential_work.any?
              fib(sequential_work.pop)
            else
              # No work to do, exit!
              Thread.exit
            end
          end
        end
      rescue Exception
        STDERR.puts "Error: #{$!.inspect}"
        raise
      end
    end
  end
  sleep 0.1
  puts "Working #{work_count} with #{thread_count} threads"
  last = Time.now
  mutex.unlock
  #cv.broadcast()
  threads.each { |t| t.join }
  execution_time[thread_count] = Time.now - last
end

execution_time.each_with_index do |x, i|
  puts "#{i}, #{x}"
end

Using:

$ gem list | grep irb
irb (1.2.0, default: 1.0.0)
⛄ 2.6.5 🚀  ~/Documents/projects/ruby (trunk)
$ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin17]

IRB 1.2.3 does not boot with Ruby 2.7 on my mac

Description

Here is the output:

$ irb -v
irb 1.2.3 (2020-02-15)
⛄ 2.7.0 🚀  ~/Documents/projects/heroku-buildpack-ruby (master)
$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin17]
⛄ 2.7.0 🚀  ~/Documents/projects/heroku-buildpack-ruby (master)
$ irb
Traceback (most recent call last):
	9: from /Users/rschneeman/.gem/ruby/2.7.0/bin/irb:23:in `<main>'
	8: from /Users/rschneeman/.gem/ruby/2.7.0/bin/irb:23:in `load'
	7: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.3/exe/irb:11:in `<top (required)>'
	6: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.3/lib/irb.rb:397:in `start'
	5: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.3/lib/irb.rb:397:in `new'
	4: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.3/lib/irb.rb:455:in `initialize'
	3: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.3/lib/irb.rb:455:in `new'
	2: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.3/lib/irb/context.rb:86:in `initialize'
	1: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.3/lib/irb/context.rb:86:in `new'
/Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.3/lib/irb/input-method.rb:213:in `initialize': undefined method `encoding_system_needs' for Reline:Module (NoMethodError)

Terminal Emulator

iTerm2
Mac 10.13.6
I use chruby for my version selection

IRB exits with "undefined method `split' for nil:NilClass (NoMethodError)" on empty #to_s definition in exceptions

Hi,

I just stumbled over an issue where my application raised an exception and due to a corner case in my Rails app, the exception class had an empty #to_s block.

class MyTestException < Exception
  def to_s; end
end

When this exception is raised in an IRB session, IRB fails with the following error:

Traceback (most recent call last):
        5: from (irb):1
        4: from app/lib/pushover_api/message.rb:9:in `push'
        3: from app/lib/pushover_api/request.rb:35:in `send'
        2: from app/lib/pushover_api/request.rb:54:in `validate_response!'
        1: from (byebug):1:in `validate_response!'
Traceback (most recent call last):
	30: from bin/rails:4:in `<main>'
	29: from /usr/lib64/ruby/gems/2.5.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `require'
	28: from /usr/lib64/ruby/gems/2.5.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:291:in `load_dependency'
	27: from /usr/lib64/ruby/gems/2.5.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `block in require'
	26: from /usr/lib64/ruby/gems/2.5.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	25: from /usr/lib64/ruby/gems/2.5.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
	24: from /usr/lib64/ruby/gems/2.5.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	23: from /usr/lib64/ruby/gems/2.5.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
	22: from /usr/lib64/ruby/gems/2.5.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
	21: from /usr/lib64/ruby/gems/2.5.0/gems/railties-6.0.2.1/lib/rails/commands.rb:18:in `<top (required)>'
	20: from /usr/lib64/ruby/gems/2.5.0/gems/railties-6.0.2.1/lib/rails/command.rb:46:in `invoke'
	19: from /usr/lib64/ruby/gems/2.5.0/gems/railties-6.0.2.1/lib/rails/command/base.rb:69:in `perform'
	18: from /usr/lib64/ruby/gems/2.5.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
	17: from /usr/lib64/ruby/gems/2.5.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
	16: from /usr/lib64/ruby/gems/2.5.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
	15: from /usr/lib64/ruby/gems/2.5.0/gems/railties-6.0.2.1/lib/rails/commands/console/console_command.rb:102:in `perform'
	14: from /usr/lib64/ruby/gems/2.5.0/gems/railties-6.0.2.1/lib/rails/commands/console/console_command.rb:19:in `start'
	13: from /usr/lib64/ruby/gems/2.5.0/gems/railties-6.0.2.1/lib/rails/commands/console/console_command.rb:70:in `start'
	12: from /usr/lib64/ruby/2.5.0/irb.rb:383:in `start'
	11: from /usr/lib64/ruby/2.5.0/irb.rb:427:in `run'
	10: from /usr/lib64/ruby/2.5.0/irb.rb:427:in `catch'
	 9: from /usr/lib64/ruby/2.5.0/irb.rb:428:in `block in run'
	 8: from /usr/lib64/ruby/2.5.0/irb.rb:487:in `eval_input'
	 7: from /usr/lib64/ruby/2.5.0/irb/ruby-lex.rb:231:in `each_top_level_statement'
	 6: from /usr/lib64/ruby/2.5.0/irb/ruby-lex.rb:231:in `catch'
	 5: from /usr/lib64/ruby/2.5.0/irb/ruby-lex.rb:232:in `block in each_top_level_statement'
	 4: from /usr/lib64/ruby/2.5.0/irb/ruby-lex.rb:232:in `loop'
	 3: from /usr/lib64/ruby/2.5.0/irb/ruby-lex.rb:246:in `block (2 levels) in each_top_level_statement'
	 2: from /usr/lib64/ruby/2.5.0/irb.rb:488:in `block in eval_input'
	 1: from /usr/lib64/ruby/2.5.0/irb.rb:623:in `signal_status'
/usr/lib64/ruby/2.5.0/irb.rb:530:in `block (2 levels) in eval_input': undefined method `split' for nil:NilClass (NoMethodError)

Well, it's not a blocker for me, I just make sure that the exception returns at least an empty string to bypass this issue.

undefined method `encoding_system_needs' for Reline:Module (NoMethodError)

Description

What are your expected behavior and actual behavior of your environment?
I launched irb and I got this: undefined method encoding_system_needs' for Reline:Module (NoMethodError)`

Terminal Emulator

What's your terminal emulator?
Konsole

Setting Files

Are you using ~/.irbrc and ~/.inputrc?
No, the irb command wasn't working so I installed it from gem

Support autocomplete for methods?

Hi,

Thanks for the amazing work y'all have put in here.
Just a step further, can autocompletion be supported for methods (at least, in-built)?
Like Python supports autocompletion that often helps speed up things (and more).

Can we expect this sooner or later?

IRB hangs when using lots of CPU and CTRL+c does not work

If I paste this into IRB then I cannot ever exit:

10.times.each do
  Thread.new do
    while true 
      puts "." 
    end
  end
end

If i hit CTRL+C I can see the input be registered in stdin but it never exits. I have to quit the entire tab.

$ gem list | grep irb
irb (1.2.0, default: 1.0.0)
⛄ 2.6.5 🚀  ~/Documents/projects/ruby (trunk)
$ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin17]

Up arrow does not work with Ruby 2.7.x on macOS

Description

👋

I'm running into this weird issue and am not really sure if this is the right place to report, but here we go:

When I'm using Ruby 2.7.0 or Ruby 2.7.1 on macOS 10.15.5, irb does not work with using the arrow keys for navigating the history.

E.g. if I do the following:

irb in Terminal
Enter puts "foo" and hit Return
Hit arrow key up -> Nothing happens
Funnily enough, CTRL^R brings up reverse search for history, as expected.

If I switch to Ruby 2.6.x (any version), Ruby 2.8.0-dev or even Ruby 2.3.1 irb works as expected. Both 2.7.0 and 2.7.1 do not work.

I've tried installing the versions a new and even reinstalled readline from Homebrew. The build output even mentions it is using Homebrew's readline.

Readline version: 8.0.4

I've set up a Ubuntu 20.04 VM with rbenv to test if the problem happens there as well and it doesn't, so it seems to be something with my Mac setup.

Maybe you, kind reader, heard about this before and have an idea, because I'm really at loss here :) Thanks in advance!

Terminal Emulator

iTerm2 (Build 3.3.9)

Setting Files

Are you using ~/.irbrc and ~/.inputrc?

~/irbrc (I've tried running it with irb -f which is supposed to ignore this file)

require 'rubygems'
# require 'wirble'
require 'pp'

# Wirble.init
# Wirble.colorize

# print SQL to STDOUT
require 'logger'
if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER')
   Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
elsif defined?(Rails)
   ActiveRecord::Base.logger = Logger.new(STDOUT)
end

# Autocomplete
require 'irb/completion'

# Prompt behavior
ARGV.concat [ "--readline", "--prompt-mode", "simple" ]

# History
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"

# Easily print methods local to an object's class
class Object
  def local_methods
    (methods - Object.instance_methods).sort
  end
end

~/.inputrc

# Edit commands in Vi mode
#set editing-mode vi
# set keymap vi
#
## SMARTER TAB-COMPLETION (Readline bindings) ##

# Perform file completion in a case insensitive fashion
set completion-ignore-case on

# Treat hyphens and underscores as equivalent
set completion-map-case on

# Display matches for ambiguous patterns at first tab press
set show-all-if-ambiguous on

# Immediately add a trailing slash when autocompleting symlinks to directories
set mark-symlinked-directories on

# Use the text that has already been typed as the prefix for searching through
# commands (basically more intelligent Up/Down behavior)
"\e[A": history-search-backward
"\e[B": history-search-forward

# Do not autocomplete hidden files unless the pattern explicitly begins with a dot
set match-hidden-files off

# Show all autocomplete results at once
set page-completions off

# If there are more than 200 possible completions for a word, ask to show them all
set completion-query-items 200

# Show extra file information when completing, like `ls -F` does
set visible-stats on

# Be more intelligent when autocompleting by also looking at the text after
# the cursor. For example, when the current line is "cd ~/src/mozil", and
# the cursor is on the "z", pressing Tab will not autocomplete it to "cd
# ~/src/mozillail", but to "cd ~/src/mozilla". (This is supported by the
# Readline used by Bash 4.)
set skip-completed-text on

# Allow UTF-8 input and output, instead of showing stuff like $'\0123\0456'
set input-meta on
set output-meta on
set convert-meta off

# Use Alt/Meta + Delete to delete the preceding word
"\e[3;3~": kill-word

irb version: irb 1.2.4 (2020-05-02)
LC_CTYPE=en_US.UTF-8

Why is there no method to reprint the source within binding.irb?

Description

When using binding.irb, the local source Ruby code is printed when the debugging session starts but if it's cleared there doesn't seem to be a method to reprint it.

# irb_source.rb
def test
  binding.irb
end

test
$ ruby irb_source.rb

From: irb_source_bug.rb @ line 2 :

    1: def test
 => 2:   binding.irb
    3: end
    4:
    5: test

irb(main):001:0>

Pry and byebug both offer a way to reprint the local source around the breakpoint without quitting the session. While it's understandable that binding.irb would have fewer features, this seems like an important one.

Terminal Emulator

What's your terminal emulator? iTerm 2

Up arrow raises Encoding::UndefinedConversionError

Description

ruby 2.7.0 & irb 1.2.1 (2019-12-24), press up arrow and the following exception is raised:

irb(main):001:0> Traceback (most recent call last):
	35: from /Users/dlary/.rbenv/versions/2.7.0/bin/irb:23:in `<main>'
	34: from /Users/dlary/.rbenv/versions/2.7.0/bin/irb:23:in `load'
	33: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/irb-1.2.1/exe/irb:11:in `<top (required)>'
	32: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:398:in `start'
	31: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:469:in `run'
	30: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:469:in `catch'
	29: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:470:in `block in run'
	28: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:535:in `eval_input'
	27: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:134:in `each_top_level_statement'
	26: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:134:in `catch'
	25: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:135:in `block in each_top_level_statement'
	24: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:135:in `loop'
	23: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:138:in `block (2 levels) in each_top_level_statement'
	22: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:166:in `lex'
	21: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:516:in `block in eval_input'
	20: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:693:in `signal_status'
	19: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb.rb:517:in `block (2 levels) in eval_input'
	18: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/irb/input-method.rb:258:in `gets'
	17: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/forwardable.rb:235:in `readmultiline'
	16: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/forwardable.rb:235:in `readmultiline'
	15: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:170:in `readmultiline'
	14: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:232:in `inner_readline'
	13: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:232:in `loop'
	12: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:233:in `block in inner_readline'
	11: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:262:in `read_io'
	10: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:262:in `loop'
	 9: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:286:in `block in read_io'
	 8: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:234:in `block (2 levels) in inner_readline'
	 7: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:234:in `each'
	 6: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline.rb:235:in `block (3 levels) in inner_readline'
	 5: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:829:in `input_key'
	 4: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:787:in `normal_char'
	 3: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:758:in `process_key'
	 2: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:1109:in `ed_insert'
	 1: from /Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline/unicode.rb:70:in `get_mbchar_width'
/Users/dlary/.rbenv/versions/2.7.0/lib/ruby/2.7.0/reline/unicode.rb:70:in `encode': "\\xCF" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)

Terminal Emulator

What's your terminal emulator? iTerm2

Pertinent environment variables:

LANG=en_US.UTF-8
LC_TERMINAL=iTerm2
LC_TERMINAL_VERSION=3.3.9
TERM=xterm
TERM_PROGRAM=iTerm.app
TERM_PROGRAM_VERSION=3.3.9

Value is not output after assignment

If I paste this code into IRB then I get no output from the last line:

def fib( n )
  return  n  if ( 0..1 ).include? n
  ( fib( n - 1 ) + fib( n - 2 ) )
end

var = fib(20)

It makes it look like the calcualtion did not succeed or there was no value. To get an output I need:

def fib( n )
  return  n  if ( 0..1 ).include? n
  ( fib( n - 1 ) + fib( n - 2 ) )
end

var = fib(20)
var

This is confusing and diverges from previous behavior.

$ gem list | grep irb
irb (1.2.0, default: 1.0.0)
⛄ 2.6.5 🚀  ~/Documents/projects/ruby (trunk)
$ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin17]

Pasting this program causes IRB to crash

Description

Paste this into IRB:

class Foo

  def foo?
  end
end

f = Foo.new

require 'benchmark/ips'

Benchmark.ips do |x|
  x.report("respond_to") {
    f.respond_to?(:foo?)
  }
  x.report("is_a?") { 
    f.is_a?(Foo)
  }
  x.compare!
end

It should not crash, but it does:

$ irb
irb(main):001:1* class Foo
irb(main):002:1*
irb(main):003:2*   def foo?
irb(main):004:1*   end
irb(main):005:0> end
=> :foo?
irb(main):006:0>
irb(main):007:0> f = Foo.new
irb(main):008:0>
irb(main):009:0> require 'benchmark/ips'
=> true
irb(main):010:0>
irb(main):011:1* Benchmark.ips do |x|
irb(main):012:2*   x.report("respond_to") {
irb(main):013:2*     f.respond_to?(:foo?)
irb(main):014:1*   }
irb(main):015:2* x.report("is_a?") {
irb(main):016:2*   f.is_a?(Foo)
irb(main):017:1* }
irb(main):018:1*   x.compare!Traceback (most recent call last):
	32: from /Users/rschneeman/.rubies/ruby-2.7.0/bin/irb:23:in `<main>'
	31: from /Users/rschneeman/.rubies/ruby-2.7.0/bin/irb:23:in `load'
	30: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/exe/irb:11:in `<top (required)>'
	29: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb.rb:398:in `start'
	28: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb.rb:469:in `run'
	27: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb.rb:469:in `catch'
	26: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb.rb:470:in `block in run'
	25: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb.rb:535:in `eval_input'
	24: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb/ruby-lex.rb:134:in `each_top_level_statement'
	23: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb/ruby-lex.rb:134:in `catch'
	22: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb/ruby-lex.rb:135:in `block in each_top_level_statement'
	21: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb/ruby-lex.rb:135:in `loop'
	20: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb/ruby-lex.rb:138:in `block (2 levels) in each_top_level_statement'
	19: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb/ruby-lex.rb:166:in `lex'
	18: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb.rb:516:in `block in eval_input'
	17: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb.rb:693:in `signal_status'
	16: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb.rb:517:in `block (2 levels) in eval_input'
	15: from /Users/rschneeman/.gem/ruby/2.7.0/gems/irb-1.2.1/lib/irb/input-method.rb:258:in `gets'
	14: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/forwardable.rb:235:in `readmultiline'
	13: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/forwardable.rb:235:in `readmultiline'
	12: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:170:in `readmultiline'
	11: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:232:in `inner_readline'
	10: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:232:in `loop'
	 9: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:233:in `block in inner_readline'
	 8: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:262:in `read_io'
	 7: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:262:in `loop'
	 6: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:303:in `block in read_io'
	 5: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:234:in `block (2 levels) in inner_readline'
	 4: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:234:in `each'
	 3: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:235:in `block (3 levels) in inner_readline'
	 2: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:835:in `input_key'
	 1: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:855:in `process_auto_indent'
/Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:855:in `*': negative argument (ArgumentError)

Terminal Emulator

iterm2 on a mac

$ irb -v
irb 1.2.1 (2019-12-24)
$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin17]

⌘+Backspace cause Encoding::UndefinedConversionError

Version:
irb 1.2.1 (2019-12-24)

Crash log:

$ irb                                                    ‹ruby-2.7.0›
2.7.0 :001 > Traceback (most recent call last):
        35: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/bin/irb:23:in `<main>'
        34: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/bin/irb:23:in `load'
        33: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/gems/irb-1.2.1/exe/irb:11:in `<top (required)>'
        32: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:398:in `start'
        31: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:469:in `run'
        30: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:469:in `catch'
        29: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:470:in `block in run'
        28: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:535:in `eval_input'
        27: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:134:in `each_top_level_statement'
        26: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:134:in `catch'
        25: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:135:in `block in each_top_level_statement'
        24: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:135:in `loop'
        23: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:138:in `block (2 levels) in each_top_level_statement'
        22: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/ruby-lex.rb:166:in `lex'
        21: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:516:in `block in eval_input'
        20: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:693:in `signal_status'
        19: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb.rb:517:in `block (2 levels) in eval_input'
        18: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/irb/input-method.rb:258:in `gets'
        17: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/forwardable.rb:235:in `readmultiline'
        16: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/forwardable.rb:235:in `readmultiline'
        15: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:170:in `readmultiline'
        14: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:232:in `inner_readline'
        13: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:232:in `loop'
        12: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:233:in `block in inner_readline'
        11: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:262:in `read_io'
        10: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:262:in `loop'
         9: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:286:in `block in read_io'
         8: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:234:in `block (2 levels) in inner_readline'
         7: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:234:in `each'
         6: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline.rb:235:in `block (3 levels) in inner_readline'
         5: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:829:in `input_key'
         4: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:787:in `normal_char'
         3: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:758:in `process_key'
         2: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline/line_editor.rb:1109:in `ed_insert'
         1: from /Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline/unicode.rb:70:in `get_mbchar_width'
/Users/beyarz/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline/unicode.rb:70:in `encode': "\\xF7" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)

completion for Symbols

Description

completion for Symbols in multiline mode doesn't work well.

What are your expected behavior and actual behavior of your environment?

(TAB) is hit TAB key

expected:

$ irb -f --nomultiline
irb(main):001:0> :verify_t(TAB)ransient_heap_internal_consistency

actual:

$ irb -f --multiline
irb(main):001:0> :verify_t(TAB)(TAB)
:verify_t
:verify_transient_heap_internal_consistency
irb(main):001:0> :verify_tr(TAB)(TAB)
:verify_tr
:verify_transient_heap_internal_consistency
irb(main):001:0> :verify_tra(TAB)(TAB)
:verify_tra
:verify_transient_heap_internal_consistency

In multiline mode irb calls Ripper.lex and RubyVM::InstructionSequence.compile with the intermediate input string, and they create new Symbol, then the completion doesn't go as planned. Is this unavoidable? Global variables are in a similar situation.

Terminal Emulator

What's your terminal emulator? gnome-terminal / xterm on Linux

Formatting of pasted code is broken

When I paste in this code into IRB:

require 'thread'
def fib( n )
  return  n  if ( 0..1 ).include? n
  ( fib( n - 1 ) + fib( n - 2 ) )
end
thread_execution_time = Hash.new {|h, k| h[k] = [] }
mutex = Mutex.new
cv = ConditionVariable.new
execution_time = []
thread_count = 1
work_count = 512
(1..128).each do |thread_count|
  cpu_work = Array.new(work_count, 20)
  threads = []
  thread_count.times.each do
    threads << Thread.new do
      mutex.synchronize { cv.wait(mutex) }
      while fib_work = cpu_work.pop
        fib(fib_work)
      end
    end
  end
  sleep 0.1
  puts "Working #{work_count} with #{thread_count} threads"
  last = Time.now
  cv.broadcast()
  threads.map(&:join)
  execution_time[thread_count] = Time.now - last
  execution_time
end
execution_time.each_with_index do |x, i|
  puts "#{i}, #{x}"
end

I get this result:

irb(main):006:0> thread_execution_time = Hash.new {|h, k| h[k] = [] }
irb(main):007:0> mutex = Mutex.new
irb(main):008:0> cv = ConditionVariable.new
irb(main):009:0> execution_time = []
irb(main):010:0> thread_count = 1
irb(main):011:0> work_count = 512
irb(main):012:0* (1..128).each do |thread_count|
irb(main):013:0* cpu_work = Array.new(work_count, 20)
irb(main):014:0* threads = []
irb(main):015:0* thread_count.times.each do
irb(main):016:0* threads << Thread.new do
irb(main):017:0* mutex.synchronize { cv.wait(mutex) }
irb(main):018:1* while fib_work = cpu_work.pop
irb(main):019:1*   fib(fib_work)
irb(main):020:0* end
irb(main):021:-* end
irb(main):022:-* end
irb(main):023:-* sleep 0.1
irb(main):024:-* puts "Working #{work_count} with #{thread_count} threads"
irb(main):025:-* last = Time.now
irb(main):026:-* cv.broadcast()
irb(main):027:-* threads.map(&:join)
irb(main):028:-* execution_time[thread_count] = Time.now - last
irb(main):029:-* execution_time
irb(main):030:-> end

Note that all the whitespace is gone in the IRB console

$ gem list | grep irb
irb (1.2.0, default: 1.0.0)
⛄ 2.6.5 🚀  ~/Documents/projects/ruby (trunk)
$ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin17]

--inf-ruby-mode semantics

Can we make it imply --nosingleline and --nomultiline, but not anything else?

In particular, we (the inf-ruby upstream) decided not to use it because it also disables continuation prompts. Currently inf-ruby uses --prompt default --noreadline instead.

But with newer features here that we can't use from Emacs, it would be helpful if --inf-ruby-mode was an option one could use to avoid version checks. In particular, if irb --inf-ruby-mode --prompt default was a valid usage in the new IRB.

problem with running irb

hello,

when i type irb inside the command line ,i get this error message
i reinstalled ruby installer again and nothing has been fixed
`

C:\WINDOWS\system32>irb
C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:4442: [BUG] Segmentation fault
ruby 2.6.5p114 (2019-10-01 revision 67812) [x64-mingw32]

-- Control frame information -----------------------------------------------
c:0032 p:---- s:0167 e:000166 CFUNC :call
c:0031 p:0018 s:0161 e:000160 METHOD C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:4442
c:0030 p:0027 s:0156 e:000155 METHOD C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:1863
c:0029 p:0192 s:0147 e:000146 METHOD C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:1997
c:0028 p:0096 s:0138 e:000137 METHOD C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:2564
c:0027 p:0024 s:0134 e:000133 METHOD C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:3849
c:0026 p:0033 s:0130 e:000129 METHOD C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:4868
c:0025 p:0066 s:0124 e:000123 METHOD C:/Ruby26-x64/lib/ruby/site_ruby/readline.rb:45
c:0024 p:0037 s:0116 e:000115 METHOD C:/Ruby26-x64/lib/ruby/2.6.0/irb/input-method.rb:151
c:0023 p:0010 s:0111 e:000110 BLOCK C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:473
c:0022 p:0025 s:0107 e:000106 METHOD C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:647
c:0021 p:0008 s:0101 e:000100 BLOCK C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:472
c:0020 p:0011 s:0098 e:000097 METHOD C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:189
c:0019 p:0010 s:0093 e:000092 METHOD C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:104
c:0018 p:0018 s:0088 e:000087 METHOD C:/Ruby26-x64/lib/ruby/2.6.0/irb/slex.rb:206
c:0017 p:0035 s:0079 e:000078 METHOD C:/Ruby26-x64/lib/ruby/2.6.0/irb/slex.rb:76
c:0016 p:0031 s:0073 e:000072 METHOD C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:292
c:0015 p:0142 s:0068 e:000067 METHOD C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:266
c:0014 p:0015 s:0061 e:000060 BLOCK C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:236 [FINISH]
c:0013 p:---- s:0057 e:000056 CFUNC :loop
c:0012 p:0006 s:0053 e:000052 BLOCK C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:232 [FINISH]
c:0011 p:---- s:0050 e:000049 CFUNC :catch
c:0010 p:0012 s:0045 e:000044 METHOD C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:231
c:0009 p:0034 s:0041 E:0009d8 METHOD C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:489
c:0008 p:0005 s:0036 e:000035 BLOCK C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:428 [FINISH]
c:0007 p:---- s:0033 e:000032 CFUNC :catch
c:0006 p:0064 s:0028 E:0002b8 METHOD C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:427
c:0005 p:0102 s:0023 e:000022 METHOD C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:383
c:0004 p:0019 s:0017 e:000016 TOP C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11 [FINISH]
c:0003 p:---- s:0014 e:000013 CFUNC :load
c:0002 p:0120 s:0009 E:001938 EVAL C:/Ruby26-x64/bin/irb.cmd:31 [FINISH]
c:0001 p:0000 s:0003 E:0017b0 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
C:/Ruby26-x64/bin/irb.cmd:31:in <main>' C:/Ruby26-x64/bin/irb.cmd:31:in load'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in <top (required)>' C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:383:in start'
C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:427:in run' C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:427:in catch'
C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:428:in block in run' C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:489:in eval_input'
C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:231:in each_top_level_statement' C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:231:in catch'
C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:232:in block in each_top_level_statement' C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:232:in loop'
C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:236:in block (2 levels) in each_top_level_statement' C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:266:in lex'
C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:292:in token' C:/Ruby26-x64/lib/ruby/2.6.0/irb/slex.rb:76:in match'
C:/Ruby26-x64/lib/ruby/2.6.0/irb/slex.rb:206:in match_io' C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:104:in getc'
C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb:189:in buf_input' C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:472:in block in eval_input'
C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:647:in signal_status' C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb:473:in block (2 levels) in eval_input'
C:/Ruby26-x64/lib/ruby/2.6.0/irb/input-method.rb:151:in gets' C:/Ruby26-x64/lib/ruby/site_ruby/readline.rb:45:in readline'
C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:4868:in readline' C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:3849:in rl_initialize'
C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:2564:in readline_initialize_everything' C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:1997:in _rl_init_terminal_io'
C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:1863:in _rl_get_screen_size' C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:4442:in call'
C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:4442:in `call'

-- C level backtrace information -------------------------------------------
C:\WINDOWS\SYSTEM32\ntdll.dll(ZwWaitForSingleObject+0x14) [0x00007ff835efc144]
C:\WINDOWS\System32\KERNELBASE.dll(WaitForSingleObjectEx+0x93) [0x00007ff8331b8ba3]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_vm_bugreport+0x2eb) [0x000000006a680c4b]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_bug_context+0x70) [0x000000006a4ce9f0]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_check_safe_obj+0x4d0) [0x000000006a5e4460]
[0x0000000000402426]
C:\WINDOWS\System32\msvcrt.dll(_C_specific_handler+0x98) [0x00007ff833fc8048]
C:\WINDOWS\SYSTEM32\ntdll.dll(_chkstk+0x11f) [0x00007ff835f011ff]
C:\WINDOWS\SYSTEM32\ntdll.dll(RtlRaiseException+0x399) [0x00007ff835eca289]
C:\WINDOWS\SYSTEM32\ntdll.dll(KiUserExceptionDispatcher+0x2e) [0x00007ff835effe6e]
C:\WINDOWS\System32\KERNELBASE.dll(GetConsoleScreenBufferInfo+0x26) [0x00007ff83318b4f6]
C:\Ruby26-x64\bin\ruby_builtin_dlls\libffi-6.dll(ffi_call_win64+0x97) [0x000000006b744797]
C:\Ruby26-x64\bin\ruby_builtin_dlls\libffi-6.dll(ffi_call+0x47) [0x000000006b7443a7]
C:\Ruby26-x64\lib\ruby\2.6.0\x64-mingw32\fiddle.so(Init_fiddle+0xb28) [0x0000000063d82dd8]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_thread_call_without_gvl+0x58) [0x000000006a62da48]
C:\Ruby26-x64\lib\ruby\2.6.0\x64-mingw32\fiddle.so(Init_fiddle+0xe3f) [0x0000000063d830ef]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_error_arity+0x131) [0x000000006a65df51]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_vm_invoke_bmethod+0xd01) [0x000000006a6685f1]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_check_funcall+0xa02) [0x000000006a673102]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_vm_exec+0x21f) [0x000000006a666c8f]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_f_eval+0x566) [0x000000006a669c16]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_rescue2+0x135) [0x000000006a4d7ba5]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_f_notimplement+0xbe2) [0x000000006a659db2]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_error_arity+0x131) [0x000000006a65df51]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_vm_invoke_bmethod+0xd01) [0x000000006a6685f1]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_check_funcall+0xaa5) [0x000000006a6731a5]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_vm_exec+0x21f) [0x000000006a666c8f]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_yield_1+0x64f) [0x000000006a66a64f]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_check_block_call+0x19d) [0x000000006a66216d]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_catch+0xa1) [0x000000006a6623d1]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_error_arity+0x131) [0x000000006a65df51]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_vm_invoke_bmethod+0xd01) [0x000000006a6685f1]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_check_funcall+0xaa5) [0x000000006a6731a5]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_vm_exec+0x21f) [0x000000006a666c8f]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_yield_1+0x64f) [0x000000006a66a64f]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_check_block_call+0x19d) [0x000000006a66216d]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_catch+0xa1) [0x000000006a6623d1]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_error_arity+0x131) [0x000000006a65df51]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_vm_invoke_bmethod+0xd01) [0x000000006a6685f1]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_check_funcall+0xaa5) [0x000000006a6731a5]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_vm_exec+0x9f5) [0x000000006a667465]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_iseqw_local_variables+0x100c) [0x000000006a528c8c]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_iseqw_local_variables+0x132b) [0x000000006a528fab]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_error_arity+0x131) [0x000000006a65df51]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_vm_invoke_bmethod+0xd01) [0x000000006a6685f1]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_check_funcall+0xa02) [0x000000006a673102]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_vm_exec+0x21f) [0x000000006a666c8f]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(rb_call_end_proc+0x15c) [0x000000006a4d291c]
C:\Ruby26-x64\bin\x64-msvcrt-ruby260.dll(ruby_run_node+0x59) [0x000000006a4d7179]
[0x0000000000402d27]
[0x00000000004013b4]
[0x000000000040150b]
C:\WINDOWS\System32\KERNEL32.DLL(BaseThreadInitThunk+0x14) [0x00007ff834057bd4]

-- Other runtime information -----------------------------------------------

  • Loaded script: irb

  • Loaded features:

    0 enumerator.so
    1 thread.rb
    2 rational.so
    3 complex.so
    4 C:/Ruby26-x64/lib/ruby/2.6.0/x64-mingw32/enc/encdb.so
    5 C:/Ruby26-x64/lib/ruby/2.6.0/x64-mingw32/enc/trans/transdb.so
    6 C:/Ruby26-x64/lib/ruby/2.6.0/x64-mingw32/enc/windows_1252.so
    7 C:/Ruby26-x64/lib/ruby/2.6.0/x64-mingw32/rbconfig.rb
    8 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/compatibility.rb
    9 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/defaults.rb
    10 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/deprecate.rb
    11 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/errors.rb
    12 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/version.rb
    13 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/requirement.rb
    14 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/platform.rb
    15 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/basic_specification.rb
    16 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/stub_specification.rb
    17 C:/Ruby26-x64/lib/ruby/2.6.0/delegate.rb
    18 C:/Ruby26-x64/lib/ruby/2.6.0/uri/rfc2396_parser.rb
    19 C:/Ruby26-x64/lib/ruby/2.6.0/uri/rfc3986_parser.rb
    20 C:/Ruby26-x64/lib/ruby/2.6.0/uri/common.rb
    21 C:/Ruby26-x64/lib/ruby/2.6.0/uri/generic.rb
    22 C:/Ruby26-x64/lib/ruby/2.6.0/uri/file.rb
    23 C:/Ruby26-x64/lib/ruby/2.6.0/uri/ftp.rb
    24 C:/Ruby26-x64/lib/ruby/2.6.0/uri/http.rb
    25 C:/Ruby26-x64/lib/ruby/2.6.0/uri/https.rb
    26 C:/Ruby26-x64/lib/ruby/2.6.0/uri/ldap.rb
    27 C:/Ruby26-x64/lib/ruby/2.6.0/uri/ldaps.rb
    28 C:/Ruby26-x64/lib/ruby/2.6.0/uri/mailto.rb
    29 C:/Ruby26-x64/lib/ruby/2.6.0/uri.rb
    30 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/specification_policy.rb
    31 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/util/list.rb
    32 C:/Ruby26-x64/lib/ruby/2.6.0/x64-mingw32/stringio.so
    33 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/specification.rb
    34 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/exceptions.rb
    35 C:/Ruby26-x64/lib/ruby/site_ruby/2.6.0/ruby_installer/runtime/singleton.rb
    36 C:/Ruby26-x64/lib/ruby/site_ruby/2.6.0/ruby_installer/runtime.rb
    37 C:/Ruby26-x64/lib/ruby/site_ruby/2.6.0/ruby_installer/runtime/msys2_installation.rb
    38 C:/Ruby26-x64/lib/ruby/2.6.0/x64-mingw32/fiddle.so
    39 C:/Ruby26-x64/lib/ruby/2.6.0/fiddle/function.rb
    40 C:/Ruby26-x64/lib/ruby/2.6.0/fiddle/closure.rb
    41 C:/Ruby26-x64/lib/ruby/2.6.0/fiddle.rb
    42 C:/Ruby26-x64/lib/ruby/site_ruby/2.6.0/ruby_installer/runtime/dll_directory.rb
    43 C:/Ruby26-x64/lib/ruby/2.6.0/x64-mingw32/enc/utf_16le.so
    44 C:/Ruby26-x64/lib/ruby/2.6.0/x64-mingw32/enc/trans/utf_16_32.so
    45 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/defaults/operating_system.rb
    46 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/util.rb
    47 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/bundler_version_finder.rb
    48 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/dependency.rb
    49 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_gem.rb
    50 C:/Ruby26-x64/lib/ruby/2.6.0/monitor.rb
    51 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb
    52 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_warn.rb
    53 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems.rb
    54 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/path_support.rb
    55 C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/version.rb
    56 C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/core_ext/name_error.rb
    57 C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/levenshtein.rb
    58 C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/jaro_winkler.rb
    59 C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/spell_checker.rb
    60 C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/spell_checkers/name_error_checkers/clas
    s_name_checker.rb
    61 C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/spell_checkers/name_error_checkers/vari
    able_name_checker.rb
    62 C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/spell_checkers/name_error_checkers.rb
    63 C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/spell_checkers/method_name_checker.rb
    64 C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/spell_checkers/key_error_checker.rb
    65 C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/spell_checkers/null_checker.rb
    66 C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/formatters/plain_formatter.rb
    67 C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean.rb
    68 C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb
    69 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/request_set/gem_dependency_api.rb
    70 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/request_set/lockfile/parser.rb
    71 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/request_set/lockfile/tokenizer.rb
    72 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/request_set/lockfile.rb
    73 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/request_set.rb
    74 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/gem_metadata.rb
    75 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/errors.rb
    76 C:/Ruby26-x64/lib/ruby/2.6.0/set.rb
    77 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/action.rb
    78 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb
    79 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/add_vertex.rb
    80 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/delete_edge.rb
    81 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
    82 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/set_payload.rb
    83 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/tag.rb
    84 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb
    85 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb
    86 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb
    87 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/state.rb
    88 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/modules/specification_provider.rb
    89 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/delegates/resolution_state.rb
    90 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb
    91 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/resolution.rb
    92 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/resolver.rb
    93 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo/modules/ui.rb
    94 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo/lib/molinillo.rb
    95 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/molinillo.rb
    96 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/activation_request.rb
    97 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/conflict.rb
    98 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/dependency_request.rb
    99 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/requirement_list.rb
    100 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/stats.rb
    101 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/set.rb
    102 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/api_set.rb
    103 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/composed_set.rb
    104 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/best_set.rb
    105 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/current_set.rb
    106 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/git_set.rb
    107 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/index_set.rb
    108 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/installer_set.rb
    109 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/lock_set.rb
    110 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/vendor_set.rb
    111 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/source_set.rb
    112 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/specification.rb
    113 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/spec_specification.rb
    114 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/api_specification.rb
    115 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/git_specification.rb
    116 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/index_specification.rb
    117 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/installed_specification.rb
    118 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/local_specification.rb
    119 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/lock_specification.rb
    120 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver/vendor_specification.rb
    121 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/resolver.rb
    122 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/source/git.rb
    123 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/source/installed.rb
    124 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/source/specific_file.rb
    125 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/source/local.rb
    126 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/source/lock.rb
    127 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/source/vendor.rb
    128 C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/source.rb
    129 C:/Ruby26-x64/lib/ruby/2.6.0/e2mmap.rb
    130 C:/Ruby26-x64/lib/ruby/2.6.0/irb/init.rb
    131 C:/Ruby26-x64/lib/ruby/2.6.0/irb/workspace.rb
    132 C:/Ruby26-x64/lib/ruby/2.6.0/irb/inspector.rb
    133 C:/Ruby26-x64/lib/ruby/2.6.0/irb/src_encoding.rb
    134 C:/Ruby26-x64/lib/ruby/2.6.0/irb/magic-file.rb
    135 C:/Ruby26-x64/lib/ruby/2.6.0/x64-mingw32/enc/euc_jp.so
    136 C:/Ruby26-x64/lib/ruby/2.6.0/x64-mingw32/enc/windows_31j.so
    137 C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline/version.rb
    138 C:/Ruby26-x64/lib/ruby/2.6.0/x64-mingw32/etc.so
    139 C:/Ruby26-x64/lib/ruby/2.6.0/x64-mingw32/enc/trans/single_byte.so
    140 C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb
    141 C:/Ruby26-x64/lib/ruby/site_ruby/readline.rb
    142 C:/Ruby26-x64/lib/ruby/2.6.0/irb/input-method.rb
    143 C:/Ruby26-x64/lib/ruby/2.6.0/irb/output-method.rb
    144 C:/Ruby26-x64/lib/ruby/2.6.0/irb/context.rb
    145 C:/Ruby26-x64/lib/ruby/2.6.0/irb/extend-command.rb
    146 C:/Ruby26-x64/lib/ruby/2.6.0/irb/notifier.rb
    147 C:/Ruby26-x64/lib/ruby/2.6.0/irb/slex.rb
    148 C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-token.rb
    149 C:/Ruby26-x64/lib/ruby/2.6.0/irb/ruby-lex.rb
    150 C:/Ruby26-x64/lib/ruby/2.6.0/irb/locale.rb
    151 C:/Ruby26-x64/lib/ruby/2.6.0/irb/version.rb
    152 C:/Ruby26-x64/lib/ruby/2.6.0/irb.rb
    153 C:/Ruby26-x64/lib/ruby/site_ruby/2.6.0/irbrc_predefiner.rb
    154 C:/Ruby26-x64/lib/ruby/2.6.0/irb/ext/save-history.rb
    155 C:/Ruby26-x64/lib/ruby/2.6.0/irb/completion.rb

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: https://www.ruby-lang.org/bugreport.html

`

thanks

Array.join("\n") doesn't work without puts/print/p

Hi,

Here's one instance:

irb(main):001:0> x = [1,12,123]
irb(main):002:0> x.join("\n")
=> "1\n12\n123"

However, it works fine if used with puts:

irb(main):003:0> x = [1,12,123]
irb(main):004:0> puts x.join("\n")
1
12
123
=> nil

Shouldn't it be working w/o puts/print/p, too?
I'll be happy to raise a PR, too, if you concur with this?
(P.S. I am not sure if that's a bug or a feature)

Slow and odd behavior when using arrow left/right and option as meta key

Description

When attempting to move the cursor in a binding.irb session, I expect no delay and for the cursor to move seamlessly.

Terminal Emulator

What's your terminal emulator? bash
Ruby version: 2.7.0

Demo

Screen Recording 2020-03-21 at 03 22

As you can see in the GIF above, the feedback cycle between key input (left/right arrow or left/right arrow + option) is regularly extremely slow, displaying control characters or blank spaces on top of code instead of simply moving the cursor.

The cursor routinely gets stuck on a specific character and the only way to solve the problem is to hit the Enter key and try again on a newline.

irb miscalculates nest level when typing do keyword

While typing while, until and for, IRB miscalculates indent level after typing do.

Without do, everything OK.

irb(main):001:1* while false
irb(main):002:0> end
=> nil

Just after typing do (before ENTER), nest level increased. (■ is cursor)

irb(main):001:2* while false do
irb(main):002:1* end
irb(main):003:1* ■
irb(main):001:2* until true do
irb(main):002:1* end
irb(main):003:1* ■
irb(main):001:2* for i in [] do
irb(main):002:1* end
irb(main):003:1* ■

It doesn't happen with then.

irb(main):001:1* if true then
irb(main):002:0> end
=> nil

Affected: current master
Unaffected: ruby 2.6.3p62 bundled irb

Original: https://bugs.ruby-lang.org/issues/15994

`chws` w/o argument does not change current workspace to main

The document (doc/irb/irb.rd.ja) says chws or irb_change_workspace command with no arguments changes the current workspace to the home workspace (i.e. the main object assigned to self when IRB begins). This does not happen in some cases.

Using irb 1.1.0.pre.2 with MRI master (d806078237).

The following example illustrates the problem -- the second invocation of chws, without an argument, is expected to change the workspace back to main. Actually, the workspace is not changed.

irb(main):001:0> chws Object.new
=> #<Object:0x000055c15c4919e8>
irb(#<Object:0x000055c15c4919e8>):002:0> chws
=> #<Object:0x000055c15c4919e8>
irb(#<Object:0x000055c15c4919e8>):003:0>

The cause of the problem seems to be IRB::Context#change_workspace at lib/irb/ext/change-ws.rb#L32, which saves the @home_workspace (via #home_workspace) only when it is first called without arguments, while it should do so before changing the workspace.

pasting in multiline irb is slow

Tried to paste a 31-lines snippet to compare a specific benchmark (anon module's #inspect was incredibly slow in < 2.7.0).

What I found is that 2.7.0's irb is unbearably slow to paste even these small snippet.

This is a comparison between Ruby 2.4.3 with pry 0.11.0 and Ruby 2.7.0-preview3 with irb 1.1.0:

https://youtu.be/c9ENYX8VVHA

I did some other tests:

  1. ruby-2.4.3 with irb-0.9.6 and ruby-2.7.0-preview3 with irb-1.1.0 --legacy: absolutely instantaneous;
  2. ruby-2.4.3 with pry-0.11.0: almost instantaneous (I assume parsing for syntax highlighting takes some time); watch video above;
  3. ruby-2.7.0 with irb-1.1.0 and irb-1.2.0 (multiline mode): unbearably slow;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.