Project

General

Profile

Bug #13326

Forwarding methods to :method_missing produces a warning

Added by ojab (ojab ojab) 3 months ago. Updated 3 months ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:80220]

Description

Since 2.4 forwarding methods to private methods is deprecated (https://bugs.ruby-lang.org/issues/12782) and method_missing is private one, so something like

require 'forwardable'

class PostOffice
  def method_missing(*args); end
end

class Courier
  extend Forwardable

  def_delegators :@post_office, :deliver

  def initialize
    @post_office = PostOffice.new
  end
end

Courier.new.deliver

produces

/tmp/1.rb:17:in `<main>': Courier#deliver at /Users/ojab/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/forwardable.rb:156 forwarding to private method PostOffice#deliver

It's used by shoulda-marchers for object doubles.

This bug is created to know if such usage is really deprecated and will break in the future or method_missing is a special case that will be supported.

History

#1 Updated by ojab (ojab ojab) 3 months ago

  • ruby -v set to 2.4.0p0

#2 [ruby-core:80225] Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Description updated (diff)

It would need a special care, I think.

#3 [ruby-core:80245] Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Status changed from Open to Rejected

When you define method_missing method, you should define respond_to_missing? method too.

#4 [ruby-core:80250] Updated by ojab (ojab ojab) 3 months ago

Ah, hadn't known about respond_to_missing?, thanks for the advise.

Also available in: Atom PDF