Class: GrADS::Command::Variable

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

Instance Method Summary collapse

Methods inherited from Expression

#*, #+, #+@, #-, #-@, #/, #paren

Constructor Details

#initialize(file_id, name) ⇒ Variable

Returns a new instance of Variable.



67
68
69
70
71
72
73
# File 'lib/grads/command.rb', line 67

def initialize (file_id, name)
  if file_id
    @expr = [name,".",file_id].join("")
  else
    @expr = name.to_s
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *argv) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/grads/command.rb', line 89

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

Instance Method Details

#[](expr) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/grads/command.rb', line 78

def [] (expr)
  case expr
  when Hash
    spec = ["(",hash.map{ |k,v| [k,"=",v].join("") }.join(","),")"].join("")
  when String
    spec = "("+expr+")"
  else
    raise "unknown expression"
  end
  return Expression.new([@expr,spec].join(""))
end

#to_sObject Also known as: to_str



74
75
76
# File 'lib/grads/command.rb', line 74

def to_s
  return @expr
end