[ruby-core:82142] [Ruby trunk Bug#13762][Rejected] Change in `#==` in Ruby 2.4?

From: nobu@...
Date: 2017-07-24 01:17:19 UTC
List: ruby-core #82142
Issue #13762 has been updated by nobu (Nobuyoshi Nakada).

Description updated
Status changed from Open to Rejected

When you write your custom `method_missing`, you have to write your custom `respond_to_missing?` too.

----------------------------------------
Bug #13762: Change in `#==` in Ruby 2.4?
https://bugs.ruby-lang.org/issues/13762#change-65899

* Author: backus (John Backus)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Given this code:

```ruby
# frozen_string_literal: true

class MyProxy < BasicObject
  def initialize(target)
    @target = target
  end

  undef_method :==

  def method_missing(method_name, *args, &block)
    if target_respond_to?(method_name)
      @target.__send__(method_name, *args, &block)
    else
      ::Object
        .instance_method(method_name)
        .bind(@target)
        .call(*args, &block)
    end
  end

  private

  def target_respond_to?(method_name)
    ::Object
      .instance_method(:respond_to?)
      .bind(@target)
      .call(method_name, true)
  end
end

puts 'a' == MyProxy.new('a')
puts MyProxy.new('a') == 'a'
puts MyProxy.new('a') == MyProxy.new('a')
```

The output differs depending on the Ruby version:

```
$ chruby 2.3.4
$ ruby test.rb
true
true
true
$ chruby 2.4.1
$ ruby test.rb
false
true
false
```

---Files--------------------------------
test.rb (739 Bytes)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next