Skip to content

Commit

Permalink
Allow comparison with nil (#3)
Browse files Browse the repository at this point in the history
* Allow comparison with nil

* Update changelog: Allow comparison with nil
  • Loading branch information
mkllnk authored Apr 9, 2024
1 parent 57e839f commit b11cda4
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Objects can be compared to `nil` with `==`.

## [1.1.0] - 2024-01-25

### Added
Expand Down
2 changes: 2 additions & 0 deletions lib/virtual_assembly/semantizer/semantic_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def serialize(serializer)
end

def ==(other)
return false unless other.respond_to?(:semanticProperties)

semanticProperties == other.semanticProperties
end

Expand Down
2 changes: 1 addition & 1 deletion lib/virtual_assembly/semantizer/semantic_property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def value=(new_value)
end

def ==(other)
name == other.name && value == other.value
other && name == other.name && value == other.value
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
expect(object).to eq object.clone
expect(object).to eq other_clazz.new

expect(object).to_not eq nil
expect(object).to_not eq other_clazz.new("id5")
expect(object).to_not eq other_clazz.new(nil, "typeA")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
expect(green).to eq green_colour
expect(green).to_not eq green_grass
expect(green).to_not eq purple
expect(green).to_not eq nil
end
end

0 comments on commit b11cda4

Please sign in to comment.