Method: RubyPython::PyMainClass#method_missing

Defined in:
lib/rubypython/pymainclass.rb

#method_missing(name, *args, &block) ⇒ Object

Delegates any method calls on this object to the Python __main__ or __builtin__ namespaces, in that order. If a block is provided, the result of calling the Python method will be yielded as an argument to the block.

name

The name of the Python method or function to call.

args

The arguments to pass to the Python method.

block

A block to execute with the result of calling the Python

method. If a block is provided, the result of the block is returned, not the result of the Python method.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rubypython/pymainclass.rb', line 44

def method_missing(name, *args, &block)
  proxy = if main.respond_to?(name)
            main
          elsif builtin.respond_to?(name)
            builtin
          else
            super(name, *args)
          end
  result = if proxy.is_real_method?(name)
             proxy.__send__(name, *args)
           else
             proxy.__send__(:method_missing, name, *args)
           end

  if block
    block.call(result)
  else
    result
  end
end