Class: Rucas::Symbolic::UnaryOpExpr

Inherits:
Struct
  • Object
show all
Includes:
OpExpr
Defined in:
lib/rucas/symbolic.rb,
lib/rucas/rewrite.rb,
lib/rucas/symbolic.rb

Overview

Unary operations.

Direct Known Subclasses

NegExpr, PosExpr

Constant Summary

Constants included from OpExpr

OpExpr::OP_PRECEDENCE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OpExpr

#constant?, #precedence, #rewrite, #with

Methods included from Expr

make, #precedence, #rewrite, #simplify

Instance Attribute Details

#opObject

Returns the value of attribute op

Returns:

  • (Object)

    the current value of op



102
103
104
# File 'lib/rucas/symbolic.rb', line 102

def op
  @op
end

#rhsObject

Returns the value of attribute rhs

Returns:

  • (Object)

    the current value of rhs



102
103
104
# File 'lib/rucas/symbolic.rb', line 102

def rhs
  @rhs
end

Instance Method Details

#childrenObject



106
# File 'lib/rucas/symbolic.rb', line 106

def children; [rhs] end

#match(expr, bindings = {}) ⇒ Object



114
115
116
117
118
# File 'lib/rucas/rewrite.rb', line 114

def match expr, bindings = {}
  return nil unless expr.is_a?(UnaryOpExpr)
  return nil unless self.op == expr.op
  rhs.match(expr.rhs, bindings)
end

#to_s_parenObject



108
109
110
# File 'lib/rucas/symbolic.rb', line 108

def to_s_paren
  "#{self.op}(#{self.rhs.to_s_paren})"
end

#valueObject



120
121
122
123
# File 'lib/rucas/rewrite.rb', line 120

def value
  v = rhs.value
  eval "(#{v}).#{self.op}" if v
end