Class: RubyPython::PyMainClass
- Inherits:
-
BlankObject
- Object
- BlankSlate
- BlankObject
- RubyPython::PyMainClass
- Includes:
- Singleton
- Defined in:
- lib/rubypython/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
A proxy object wrapping the Python _builtin_ namespace.
-
#main ⇒ RubyPyModule
A proxy object wrapping the Python _main_ 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.
-
#update(status) ⇒ Object
For internal use only.
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/rubypython/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
Returns a proxy object wrapping the Python _builtin_ namespace.
27 28 29 |
# File 'lib/rubypython/pymainclass.rb', line 27 def builtin @builtin||=RubyPython.import "__builtin__" end |
#main ⇒ RubyPyModule
Returns a proxy object wrapping the Python _main_ namespace.
21 22 23 |
# File 'lib/rubypython/pymainclass.rb', line 21 def main @main||=RubyPython.import "__main__" end |
Instance Method Details
#update(status) ⇒ Object
For internal use only. Called by RubyPython when the interpreter is started or stopped so that the neccesary preperation or cleanup can be done.
52 53 54 55 56 57 |
# File 'lib/rubypython/pymainclass.rb', line 52 def update(status) if status.equal? :stop @main = nil @builtin = nil end end |