Skip to content

irb should not require standard libraries by default (if possible) #143

Closed as not planned

Description

@JunichiIto

In Ruby 2.6.6, you cannot use Etc constant without requring etc library:

irb(main):001:0> RUBY_DESCRIPTION
=> "ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin19]"
irb(main):002:0> Etc
Traceback (most recent call last):
        4: from /Users/jnito/.rbenv/versions/2.6.6/bin/irb:23:in `<main>'
        3: from /Users/jnito/.rbenv/versions/2.6.6/bin/irb:23:in `load'
        2: from /Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
        1: from (irb):2
NameError (uninitialized constant Etc)

But in Ruby 2.7.2, you can do it:

irb(main):001:0> RUBY_DESCRIPTION
=> "ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]"
irb(main):002:0> Etc
=> Etc

However, you cannot use Etc constant in plain script context:

$ ruby -e "puts RUBY_DESCRIPTION; Etc"
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]
Traceback (most recent call last):
-e:1:in `<main>': uninitialized constant Etc (NameError)

Etc is defined not in core API but in standard library. So Ruby does not require it by default, but irb does in Ruby 2.7. This inconsistent behavior confuses newbies. Actually I was asked such a question today.

As far as I investigated, irb requires some other libraries like fileutils, set and so on. But I think irb should run in the same context as plain script, if possible.

Activity

  1. rubyFeedback commented on Jan 3, 2021

    @rubyFeedback

    I sort of agree with JunichiIto; IRB should ideally be as close as possible to "default" ruby behaviour, as-is.

    People can customize the behaviour via irbrc, which I do too - my irbrc contains lots of load-ruby-code
    behaviour. :)

  2. sos4nt commented on Dec 6, 2022

    @sos4nt

    Set seems to be required by RubyGems, or more specifically, by its Molinillo dependency resolver:

    lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb#L158

  3. st0012 commented on Oct 25, 2023

    @st0012
    Member

    IRB as a development tool needs to prioritise features that increase developer productivity and happiness, with some of them inevitably rely on standard libraries or even bundled gems to implement. For example, the default REPL now requires Reline and RDoc for autocompletion.
    It's not possible nor practical to rewrite or even drop features to simply "make IRB sessions cleaner". So I'm closing it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions