Class: GrADS::Command::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/grads/command.rb

Direct Known Subclasses

Variable

Instance Method Summary collapse

Constructor Details

#initialize(expr) ⇒ Expression

Returns a new instance of Expression.



9
10
11
# File 'lib/grads/command.rb', line 9

def initialize (expr)
  @expr = expr
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *argv) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/grads/command.rb', line 57

def method_missing (id, *argv)
  if argv.size > 0
    return Expression.new(format("#{id}(%s,%s)", @expr, argv.join(",")))
  else
    return Expression.new(format("#{id}(%s)", @expr))
  end
end

Instance Method Details

#*(other) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/grads/command.rb', line 49

def * (other)
  case other
  when Expression
    return Expression.new([self.paren,"*",other.paren].join)
  else
    return Expression.new([self.paren,"*",other.to_s].join)
  end
end

#+(other) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/grads/command.rb', line 25

def + (other)
  case other
  when Expression
    return Expression.new([self.paren,"+",other.paren].join)
  else
    return Expression.new([self.paren,"+",other.to_s].join)
  end
end

#+@Object



22
23
24
# File 'lib/grads/command.rb', line 22

def +@
  return Expression.new(["+", self.paren].join)
end

#-(other) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/grads/command.rb', line 33

def - (other)
  case other
  when Expression
    return Expression.new([self.paren,"-",other.paren].join)
  else
    return Expression.new([self.paren,"-",other.to_s].join)
  end
end

#-@Object



19
20
21
# File 'lib/grads/command.rb', line 19

def -@
  return Expression.new(["-", self.paren].join)
end

#/(other) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/grads/command.rb', line 41

def / (other)
  case other
  when Expression
    return Expression.new([self.paren,"/",other.paren].join)
  else
    return Expression.new([self.paren,"/",other.to_s].join)
  end
end

#parenObject



15
16
17
# File 'lib/grads/command.rb', line 15

def paren
  return ["(",@expr,")"].join
end

#to_sObject Also known as: to_str



12
13
14
# File 'lib/grads/command.rb', line 12

def to_s
  return @expr
end