class BCDice::Arithmetic::Node::DivideBase
除算ノードの基底クラス
定数 ROUNDING_METHOD
で端数処理方法を示す記号 ( +'U'+, +'R'+, +''+ ) を定義すること。 また、除算および端数処理を行う divide_and_round
メソッドを実装すること。
Public Class Methods
new(lhs, rhs)
click to toggle source
ノードを初期化する @param [Object] lhs 左のオペランドのノード @param [Object] rhs 右のオペランドのノード
Calls superclass method
BCDice::Arithmetic::Node::BinaryOp::new
# File lib/bcdice/arithmetic/node.rb, line 44 def initialize(lhs, rhs) super(lhs, :/, rhs) end
Public Instance Methods
eval(round_type)
click to toggle source
# File lib/bcdice/arithmetic/node.rb, line 48 def eval(round_type) l = @lhs.eval(round_type) r = @rhs.eval(round_type) divide_and_round(l, r, round_type) end
output()
click to toggle source
メッセージへの出力を返す
通常の結果の末尾に、端数処理方法を示す記号を付加する。
@return [String]
# File lib/bcdice/arithmetic/node.rb, line 59 def output "#{super}#{rounding_method}" end
Private Instance Methods
divide_and_round(_dividend, _divisor, _round_type)
click to toggle source
除算および端数処理を行う @param [Integer] _dividend 被除数 @param [Integer] _divisor 除数(0以外) @param [Symbol] _round_type ゲームシステムの端数処理設定 @return [Integer]
# File lib/bcdice/arithmetic/node.rb, line 82 def divide_and_round(_dividend, _divisor, _round_type) raise NotImplementedError end
op_for_s_exp()
click to toggle source
S式で使う演算子の表現を返す @return [String]
# File lib/bcdice/arithmetic/node.rb, line 73 def op_for_s_exp "#{@op}#{rounding_method}" end
rounding_method()
click to toggle source
端数処理方法を示す記号を返す @return [String]
# File lib/bcdice/arithmetic/node.rb, line 67 def rounding_method self.class::ROUNDING_METHOD end