Skip to content

Commit d24b206

Browse files
committed
Use idiomatic Ruby booleans
Prefer nil? and direct boolean checks in TreeNode/TrieNode while preserving existing semantics, and ensure include? returns a boolean.
1 parent 826d878 commit d24b206

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

lib/tree.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def root?
161161
#
162162
# @return [Boolean] +true+ if the node has content.
163163
def content?
164-
@content != nil
164+
!@content.nil?
165165
end
166166

167167
alias has_content? content? # @todo: Aliased for eventual replacement

lib/tree/trie.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def initialize(name, content = nil, options = nil)
7070
#
7171
# @return [Boolean] +true+ if this is a terminal node.
7272
def terminal?
73-
@terminal == true
73+
@terminal
7474
end
7575

7676
# Inserts a word into the trie.
@@ -119,7 +119,7 @@ def <<(word)
119119
def include?(word)
120120
validate_word!(word)
121121
node = find_node(word)
122-
node&.terminal? == true
122+
!!node&.terminal?
123123
end
124124

125125
# Alias for {#include?} to support search-oriented naming.
@@ -173,7 +173,7 @@ def words_with_prefix(prefix, limit: nil)
173173
# @param [Boolean] value The terminal flag value.
174174
# @return [void]
175175
def terminal=(value)
176-
@terminal = value == true
176+
@terminal = value.equal?(true)
177177
end
178178

179179
# Validate that the word is a non-empty string.

0 commit comments

Comments
 (0)