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

View file

@ -14,9 +14,16 @@ module Spectator
# Creates the value. # Creates the value.
# Expects the *value* of the expression and a *label* describing it. # Expects the *value* of the expression and a *label* describing it.
# The *label* is usually the Crystal code evaluating to the *value*. # 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) def initialize(@value : T, label : Label)
super(label) super(label)
end 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
end end