Method: Tap::App#var

Defined in:
lib/tap/app.rb

#var(obj, auto_assign = true) ⇒ Object

Returns the variable for the object. If the object is not assigned to a variable and auto_assign is true, then the object is set to an unused variable and the new variable is returned.

The new variable will be an integer and will be removed upon gc.



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/tap/app.rb', line 309

def var(obj, auto_assign=true)
  objects.each_pair do |var, object|
    return var if obj == object
  end
  
  return nil unless auto_assign
  
  var = objects.length
  loop do 
    if objects.has_key?(var)
      var += 1
    else
      set(var, obj)
      return var
    end
  end
end