Class: BCDice::Arithmetic::Node::BinaryOp
- Inherits:
-
Object
- Object
- BCDice::Arithmetic::Node::BinaryOp
- Defined in:
- lib/bcdice/arithmetic/node.rb
Direct Known Subclasses
Instance Method Summary collapse
- #eval(round_type) ⇒ Object
-
#initialize(lhs, op, rhs) ⇒ BinaryOp
constructor
A new instance of BinaryOp.
-
#op_for_s_exp ⇒ String
S式で使う演算子の表現.
-
#output ⇒ String
メッセージへの出力.
-
#s_exp ⇒ String
ノードのS式.
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_exp ⇒ String
Returns S式で使う演算子の表現.
30 31 32 |
# File 'lib/bcdice/arithmetic/node.rb', line 30 def op_for_s_exp @op end |
#output ⇒ String
Returns メッセージへの出力.
20 21 22 |
# File 'lib/bcdice/arithmetic/node.rb', line 20 def output "#{@lhs.output}#{@op}#{@rhs.output}" end |
#s_exp ⇒ String
Returns ノードの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 |