Class: Rupy::PyMainClass
- Inherits:
-
BlankObject
- Object
- BlankSlate
- BlankObject
- Rupy::PyMainClass
- Includes:
- Singleton
- Defined in:
- lib/rupy/pymainclass.rb
Overview
A singleton object providing access to the python _main_ and _builtin_ modules. This can be conveniently accessed through the already instaniated PyMain constant. The _main_ namespace is searched before the _builtin_ namespace. As such, naming clashes will be resolved in that order.
## Block Syntax The PyMainClass object provides somewhat experimental block support. A block may be passed to a method call and the object returned by the function call will be passed as an argument to the block.
Instance Attribute Summary collapse
-
#builtin ⇒ RubyPyModule
namespace.
-
#main ⇒ RubyPyModule
namespace.
Instance Method Summary collapse
-
#method_missing(name, *args, &block) ⇒ Object
Delegates any method calls on this object to the Python _main_ or _builtin_ namespaces.
Methods inherited from BlankObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Delegates any method calls on this object to the Python _main_ or _builtin_ namespaces. Method call resolution occurs in that order.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rupy/pymainclass.rb', line 33 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 block ? block.call(result) : result end |
Instance Attribute Details
#builtin ⇒ RubyPyModule
namespace.
27 28 29 |
# File 'lib/rupy/pymainclass.rb', line 27 def builtin @builtin ||= Rupy.import "__builtin__" end |
#main ⇒ RubyPyModule
namespace.
21 22 23 |
# File 'lib/rupy/pymainclass.rb', line 21 def main @main ||= Rupy.import "__main__" end |