Skip to content

Implement '==' operator for entries #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 29, 2020
Merged

Conversation

erlliam
Copy link
Contributor

@erlliam erlliam commented Oct 14, 2020

Hey @HarlemSquirrel I was going through your profile and saw this repository. This issue seemed like something I could solve.

Resolves #372

@@ -196,4 +196,8 @@ def setter?(sym)
sym.to_s[-1] == ?=
end
private :setter?

def ==(other)
return @myhash == other.to_h
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return @myhash == other.to_h
@myhash == other.to_h

Also, should this method check if the other is the same class?

@erlliam
Copy link
Contributor Author

erlliam commented Oct 15, 2020

Should the equal operator work for sub classes of entries ? I was going to write other.class == self.class instead of instance_of?, but I felt like the latter is probably the better choice. Is there any difference between those two?

@HarlemSquirrel
Copy link
Member

HarlemSquirrel commented Oct 16, 2020

While we don't really have an exposed way to create objects that inherit from Net::LDAP::Entry I would say those would be OK to consider equal as far as Class goes. For Ruby Hash objects == Returns true if all of the following are true:

  • object is a Hash object.
  • hash and object have the same keys (regardless of order).
  • For each key key, hash[key] == object[key].

@HarlemSquirrel
Copy link
Member

@erlliam other.class == self.class and other.instance_of?(self.class) are doing essentially the same thing. The late does feel more to the spirit of Ruby where we often prefer what sounds or looks more "natural".

Copy link
Member

@HarlemSquirrel HarlemSquirrel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@HarlemSquirrel HarlemSquirrel merged commit 8c4b201 into ruby-ldap:master Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement ==
3 participants