Class: BCDice::Arithmetic::Node::BinaryOp

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/arithmetic/node.rb

Direct Known Subclasses

DivideBase

Instance Method Summary collapse

Constructor Details

#initialize(lhs, op, rhs) ⇒ BinaryOp

Returns a new instance of BinaryOp.



7
8
9
10
11
# File 'lib/bcdice/arithmetic/node.rb', line 7

def initialize(lhs, op, rhs)
  @lhs = lhs
  @op = op
  @rhs = rhs
end

Instance Method Details

#eval(round_type) ⇒ Object



13
14
15
16
17
# File 'lib/bcdice/arithmetic/node.rb', line 13

def eval(round_type)
  l = @lhs.eval(round_type)
  r = @rhs.eval(round_type)
  l.send(@op, r)
end

#op_for_s_expString

Returns S式で使う演算子の表現.

Returns:

  • (String)

    S式で使う演算子の表現



30
31
32
# File 'lib/bcdice/arithmetic/node.rb', line 30

def op_for_s_exp
  @op
end

#outputString

Returns メッセージへの出力.

Returns:

  • (String)

    メッセージへの出力



20
21
22
# File 'lib/bcdice/arithmetic/node.rb', line 20

def output
  "#{@lhs.output}#{@op}#{@rhs.output}"
end

#s_expString

Returns ノードのS式.

Returns:

  • (String)

    ノードのS式



25
26
27
# File 'lib/bcdice/arithmetic/node.rb', line 25

def s_exp
  "(#{op_for_s_exp} #{@lhs.s_exp} #{@rhs.s_exp})"
end