mirror of
https://gitea.invidious.io/iv-org/shard-radix.git
synced 2024-08-15 00:43:21 +00:00
Fix incorrect return type
`Result#key` is expected to be `String`, yet Crystal considered that by branching is possible result to be `nil`. This was caused by *return-early* approach: def foo return @foo if @foo @foo = "awesome" end pp typeof(foo) # => String? Changed to instead use memoization technique.
This commit is contained in:
parent
2c9279e51e
commit
be420ec875
1 changed files with 7 additions and 9 deletions
|
@ -61,15 +61,13 @@ module Radix
|
|||
# # => ""
|
||||
# ```
|
||||
def key : String
|
||||
return @key if @key
|
||||
|
||||
key = String.build { |io|
|
||||
@key ||= begin
|
||||
String.build { |io|
|
||||
@nodes.each do |node|
|
||||
io << node.key
|
||||
end
|
||||
}
|
||||
|
||||
@key = key
|
||||
end
|
||||
end
|
||||
|
||||
# Adjust result information by using the details of the given `Node`.
|
||||
|
|
Loading…
Reference in a new issue