Skip to content

Handle array attributes in hash/equality methods.#28

Merged
chrisgibson merged 3 commits into
masterfrom
fix/array-attribute-equality
May 1, 2017
Merged

Handle array attributes in hash/equality methods.#28
chrisgibson merged 3 commits into
masterfrom
fix/array-attribute-equality

Conversation

@chrisgibson
Copy link
Copy Markdown
Contributor

Problem

Array attributes are not handled in #==, #eql?, and #hash. A TypeError is raised when calling send with the attribute within #== and hash.

Solution

Unwrap array attribute names (similar to .initialize) in the #== and #hash methods.

Copy link
Copy Markdown
Contributor

@davetron5000 davetron5000 left a comment

Choose a reason for hiding this comment

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

👍

Comment thread lib/immutable-struct.rb
return false unless other.is_a?(klass)
attributes.all? { |attribute| self.send(attribute) == other.send(attribute) }
attributes.all? do |attribute|
if attribute.kind_of?(Array) and attribute.size == 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this because attribute is using that syntax [:widgets]?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's right... for array attributes, we're trying to send that to the instance send([:widgets])...

@sipple
Copy link
Copy Markdown
Contributor

sipple commented May 1, 2017

Curious about the failure in travis for rbx-2, as it's passing on everything else. I'm not actually sure what rbx-2 is, but it seems to have been failing for a while. Is this a long term issue that we're not dealing with?

@davetron5000
Copy link
Copy Markdown
Contributor

rbx is rubinius. It says there are no binaries to download, so maybe that's not the right name for Rubinius? Latest is version 3, so let's try rbx-3 and if that doesn't work, let's just remove it.

@sipple
Copy link
Copy Markdown
Contributor

sipple commented May 1, 2017

@davetron5000 👍

@chrisgibson chrisgibson merged commit 56a7eb6 into master May 1, 2017
@chrisgibson chrisgibson deleted the fix/array-attribute-equality branch May 1, 2017 20:03
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.

3 participants