class BCDice::CommonCommand::Calc::Node::Command
Public Class Methods
new(secret:, expr:)
click to toggle source
# File lib/bcdice/common_command/calc/node.rb, line 10 def initialize(secret:, expr:) @secret = secret @expr = expr end
Public Instance Methods
eval(round_type)
click to toggle source
# File lib/bcdice/common_command/calc/node.rb, line 15 def eval(round_type) value = begin @expr.eval(round_type) rescue ZeroDivisionError "ゼロ除算が発生したため計算できませんでした" end output = if @expr.is_a?(Arithmetic::Node::Parenthesis) @expr.output else "(#{@expr.output})" end Result.new.tap do |r| r.secret = @secret r.text = "c#{output} > #{value}" end end