Class: Tcl::Proc

Inherits:
Object
  • Object
show all
Includes:
InterpHelper
Defined in:
lib/tcl/proc.rb

Constant Summary collapse

BUILTINS =
%w(
  auto_execok auto_import auto_load auto_load_index 
  auto_qualify tclLog unknown
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from InterpHelper

#_, #_!, included, #method_missing

Constructor Details

#initialize(interp, name) ⇒ Proc

Returns a new instance of Proc.



12
13
14
15
16
# File 'lib/tcl/proc.rb', line 12

def initialize(interp, name)
  @interp = interp
  @name = name.to_s
  to_tcl
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Tcl::InterpHelper

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/tcl/proc.rb', line 10

def name
  @name
end

Instance Method Details

#argumentsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tcl/proc.rb', line 18

def arguments
  list_to_array(_!(:info, :args, name)).map do |argument_name|
    begin
      variable_name = "__Tcl_Proc_arguments_#{name}_#{argument_name}"
      if _!(:info, :default, name, argument_name, variable_name) == "0"
        argument_name
      else
        _(argument_name, var(variable_name).value)
      end
    ensure
      _!(:unset, variable_name)
    end
  end
end

#bodyObject



33
34
35
# File 'lib/tcl/proc.rb', line 33

def body
  _!(:info, :body, name)
end

#builtin?Boolean

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/tcl/proc.rb', line 45

def builtin?
  # TODO should also check to see if the definition has changed
  BUILTINS.include?(name) 
end

#call(*args) ⇒ Object



37
38
39
# File 'lib/tcl/proc.rb', line 37

def call(*args)
  _!(name, *args.map { |arg| arg.to_s })
end

#to_tclObject



41
42
43
# File 'lib/tcl/proc.rb', line 41

def to_tcl
  _(:proc, name, _(*arguments), body)
end