Handle nil labels

This commit is contained in:
Michael Miller 2021-01-16 11:11:42 -07:00
parent 0992bad7eb
commit 97923d6bcd
No known key found for this signature in database
GPG Key ID: FB9F12F7C646A4AD
2 changed files with 10 additions and 3 deletions

View File

@ -16,7 +16,7 @@ module Spectator
# The *proc* will be called to evaluate the value of the expression.
# The *label* is usually the Crystal code for the *proc*.
# It can be nil if it isn't available.
def initialize(@block : -> T, label : Label)
def initialize(@block : -> T, label : Label = nil)
super(label)
end
@ -24,7 +24,7 @@ module Spectator
# The block will be called to evaluate the value of the expression.
# The *label* is usually the Crystal code for the *block*.
# It can be nil if it isn't available.
def initialize(label : Label, &@block : -> T)
def initialize(label : Label = nil, &@block : -> T)
super(label)
end

View File

@ -14,9 +14,16 @@ module Spectator
# Creates the value.
# Expects the *value* of the expression and a *label* describing it.
# The *label* is usually the Crystal code evaluating to the *value*.
# It can be nil if it isn't available.
def initialize(@value : T, label : Label)
super(label)
end
# Creates the value.
# Expects the *value* of the expression.
# It can be nil if it isn't available.
# A label is generated by calling `#inspect` on the *value*.
def initialize(@value : T)
super(@value.inspect)
end
end
end