Class: PyMainClass
- Inherits:
-
RubyPythonBridge::BlankObject
- Object
- RubyPythonBridge::BlankObject
- PyMainClass
- Includes:
- Singleton
- Defined in:
- lib/rubypython/wrapper_extensions.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 beofre 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 ⇒ Object
:nodoc:.
-
#main ⇒ Object
:nodoc:.
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
:nodoc:
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rubypython/wrapper_extensions.rb', line 32 def method_missing(name,*args,&block) begin result=main.send(name,*args) rescue NoMethodError begin result=builtin.send(name,*args) rescue NoMethodError super(name,*args) end end if(block) return block.call(result) end result end |
Instance Attribute Details
#builtin ⇒ Object
:nodoc:
27 28 29 |
# File 'lib/rubypython/wrapper_extensions.rb', line 27 def builtin @builtin||=RubyPython.import "__builtin__" end |
#main ⇒ Object
:nodoc:
22 23 24 |
# File 'lib/rubypython/wrapper_extensions.rb', line 22 def main @main||=RubyPython.import "__main__" end |