lib/dolos/result.rb in dolos-0.2.0 vs lib/dolos/result.rb in dolos-0.2.1
- old
+ new
@@ -53,15 +53,24 @@
Success.new(val, length, captures)
end
end
class Failure < Result
- attr_reader :message, :error_position, :state
+ attr_reader :error_position, :state
- def initialize(message, error_position, state)
- @message = message
+ def initialize(message_proc, error_position, state)
+ @message_proc = message_proc
@error_position = error_position
@state = state
+ @message_evaluated = false
+ end
+
+ def message
+ unless @message_evaluated
+ @message_value = @message_proc.call
+ @message_evaluated = true
+ end
+ @message_value
end
def inspect
pretty_print
end