From: "byroot (Jean Boussier) via ruby-core" <ruby-core@...>
Date: 2024-02-19T08:08:10+00:00
Subject: [ruby-core:116840] [Ruby master Misc#20279] Is the implementation of `respond_to_missing?` in BasicObject documentation correct?

Issue #20279 has been updated by byroot (Jean Boussier).


So yes, the documentation is incorrect.

----------------------------------------
Misc #20279: Is the implementation of `respond_to_missing?` in BasicObject documentation correct?
https://bugs.ruby-lang.org/issues/20279#change-106866

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
----------------------------------------
Considering the documentation here: https://ruby-doc.org/3.2.2/BasicObject.html

Introduced in: https://github.com/ruby/ruby/commit/3eb7d2b33e3f8555d81db5369eb6fb7100a91e63

I wondered if `or super` is correct in `respond_to_missing?`.

For example:

```
irb(main):001* class MyObjectSystem < BasicObject
irb(main):002*   DELEGATE = [:puts, :p]
irb(main):003* 
irb(main):004*   def method_missing(name, *args, &block)
irb(main):005*     return super unless DELEGATE.include? name
irb(main):006*     ::Kernel.send(name, *args, &block)
irb(main):007*   end
irb(main):008* 
irb(main):009*   public def respond_to_missing?(name, include_private = false)
irb(main):010*     DELEGATE.include?(name) or super
irb(main):011*   end
irb(main):012> end
=> :respond_to_missing?
irb(main):013> MyObjectSystem.new.respond_to_missing?(:foo)
(irb):5:in `method_missing': super: no superclass method `respond_to_missing?' for an instance of MyObjectSystem (NoMethodError)
	from (irb):10:in `respond_to_missing?'
	from (irb):13:in `<main>'
	from <internal:kernel>:187:in `loop'
	from /home/samuel/.gem/ruby/3.3.0/gems/irb-1.11.2/exe/irb:9:in `<top (required)>'
	from /home/samuel/.gem/ruby/3.3.0/bin/irb:25:in `load'
	from /home/samuel/.gem/ruby/3.3.0/bin/irb:25:in `<main>'
```

It looks wrong to me.

In addition, I'd like to know in what situations `BasicObject` should define `respond_to_missing?` - because I was under the impression it was called by `method_missing`. Does `BasicObject#method_missing` have this behaviour? Maybe we can improve the documentation cc @burdettelamar 



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/