Understanding Comparison Operators Used to Determine Group_by Equivalence

Asked 5 months ago, Updated 5 months ago, 10 views

How to display aliases for specific methods

When I asked you a question, I found that group_by's equivalence decision was not == or eql? but I couldn't find the document when I looked for what was being used.

I searched ruby source code by def group_by, but found only test code...


Under what conditions does group_by determine that they are identical?


2022-09-30 14:12

1 Answers

If group_by is used to assemble a hash, it would be hash.

This is what happened when I tried it.

 irb(main): 043:0>a=Object.instance_method(:debugger)
irb(main): 044:0>b=Object.instance_method(:byebug)
irb(main): 045:0>a==b
irb(main): 046:0>a.eql?(b)
irb(main): 047:0>a.hash==b.hash
irb(main): 048:0>Hash.instance_method(:has_key?).hash==Hash.instance_method(:member?).hash

The Object#hash documentation contains

If A.eql?(B), then A.hash==B.hash

You must meet the relationship.

It says, but the above behavior doesn't seem to be the same

2022-09-30 14:12

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.