Project

General

Profile

Actions

Bug #13326

closed

Forwarding methods to :method_missing produces a warning

Added by ojab (ojab ojab) over 7 years ago. Updated over 7 years ago.

Status:
Rejected
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.

Actions #1

Updated by ojab (ojab ojab) over 7 years ago

  • ruby -v set to 2.4.0p0

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

  • Description updated (diff)

It would need a special care, I think.

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

  • Status changed from Open to Rejected

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

Updated by ojab (ojab ojab) over 7 years ago

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0