Skip to content

[Bug] irb does not allow me to overwrite irb's core methods #839

@rubyFeedback

Description

@rubyFeedback

irb comes with some built in methods such as "ls".

When I type "ls" I get this dropdown menu result:

https://i.imgur.com/MHoICC9.png

When I then try to re-define ls as a method, irb ignores it:

https://i.imgur.com/Bp0xGcV.png

Meaning, when I then type "ls" again, my own custom
defined method is ignored, and the built-in is called,
which leads to the dropdown menu shown in the first
image on imgur.

The input I used for the method definition in the second image
was as follows:

ls

def ls
  puts 'OK'
end

ls

This was on a vanilla IRB.

I believe this is a change to prior IRB versions. In older IRB versions,
I think, we could re-define such methods without a problem. With
the rewrite of irb, we no longer can.

I believe that this functionality is a bug, not solely because it modified
the old behaviour, but more importantly because irb should test RUBY's
default behaviour, and in a .rb file I can define a method called "ls" just
fine, without irb interfering. So I believe this is a bug both in behaviour,
as well as in intent.

How would I propose to change this?

Well, I believe it is ok if you want to make "ls" as a default behaviour
available - but NOT if you ignore and prevent the user from defining
a method called "ls" (or any other in-built method - see my other
prior bug report). The latter I consider behaviour that should not
happen.

As a compromise the proper way to handle this is to perhaps show
a warning (optionally also allow to disable this warning somehow),
but to allow the user to re-define that behaviour. Internally you can
always use methods such as "ls" as "irb_ls" or some variant nobody
accidentally types.

At the least I would expect that irb documents such changes, because
to me it was super-surprising to find out that my old ruby code does
not work, when it really should work. Took me a while to change it.

PS: I also changed my old code and specifically avoid calling irb's
in-built methods, so although I think irb's new behaviour is wrong,
it no longer affects me as I adjusted my own code base. Still I find
it rather questionable how irb suddenly changes after some 15
years or so. Either way I did report it now - what then happens is
no longer up to me. Thanks for reading this report nonetheless.

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