class BCDice::CommonCommand::AddDice::Node::BinaryOp

二項演算子のノード

Public Class Methods

new(lhs, op, rhs) click to toggle source

ノードを初期化する @param [Object] lhs 左のオペランドのノード @param [Symbol] op 演算子 @param [Object] rhs 右のオペランドのノード

# File lib/bcdice/common_command/add_dice/node.rb, line 126
def initialize(lhs, op, rhs)
  @lhs = lhs
  @op = op
  @rhs = rhs
end

Public Instance Methods

eval(game_system, randomizer) click to toggle source

ノードを評価する

左右のオペランドをそれぞれ再帰的に評価した後で、演算を行う。

@param game_system [BCDice::Base] @param randomizer [Randomizer] ランダマイザ @return [Integer] 評価結果

# File lib/bcdice/common_command/add_dice/node.rb, line 139
def eval(game_system, randomizer)
  lhs = @lhs.eval(game_system, randomizer)
  rhs = @rhs.eval(game_system, randomizer)

  return calc(lhs, rhs, game_system.round_type)
end
expr(game_system) click to toggle source

文字列に変換する @return [String]

# File lib/bcdice/common_command/add_dice/node.rb, line 153
def expr(game_system)
  lhs = @lhs.expr(game_system)
  rhs = @rhs.expr(game_system)

  "#{lhs}#{@op}#{rhs}"
end
include_dice?() click to toggle source

@return [Boolean]

# File lib/bcdice/common_command/add_dice/node.rb, line 147
def include_dice?
  @lhs.include_dice? || @rhs.include_dice?
end
output() click to toggle source

メッセージへの出力を返す @return [String]

# File lib/bcdice/common_command/add_dice/node.rb, line 162
def output
  "#{@lhs.output}#{@op}#{@rhs.output}"
end
s_exp() click to toggle source

ノードのS式を返す @return [String]

# File lib/bcdice/common_command/add_dice/node.rb, line 168
def s_exp
  "(#{op_for_s_exp} #{@lhs.s_exp} #{@rhs.s_exp})"
end

Private Instance Methods

calc(lhs, rhs, _round_type) click to toggle source

演算を行う @param lhs [Integer] lhs 左のオペランド @param rhs [Integer] 右のオペランド @param _round_type [Symbol] ゲームシステムの端数処理設定 @return [Integer] 演算の結果

# File lib/bcdice/common_command/add_dice/node.rb, line 179
def calc(lhs, rhs, _round_type)
  lhs.send(@op, rhs)
end
op_for_s_exp() click to toggle source

S式で使う演算子の表現を返す @return [String]

# File lib/bcdice/common_command/add_dice/node.rb, line 185
def op_for_s_exp
  @op
end