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 |