Module: ObjC
The ObjC module contains the main elements of RubyObjC, a bridge connecting the Ruby and Objective-C programming languages. RubyObjC allows code written in Ruby and Objective-C to be easily mixed, yielding software implementations that exploit the strengths of both languages.
- Ruby wrappers exist for Objective-C classes (ObjC::Class), methods (ObjC::Method), instance variables (ObjC::Variable), and objects (ObjC::Object), giving Ruby programs direct access to the Objective-C runtime.
- Objective-C objects are accessible using Ruby wrappers that are instances of classes derived from ObjC::Object. Using information obtained from the ObjC::Class and ObjC::Method interfaces, these wrappers are given handlers for Objective-C methods to allow Ruby calls to Objective-C methods.
- When the Ruby wrapper class for a class of Objective-C objects is subclassed, a new Objective-C class is created automatically. Handlers for Ruby methods of the new subclass are added to allow those Ruby methods to be called from Objective-C. This is done using methods of ObjC::Class.
- Ruby wrappers for C functions can be created at runtime to allow Ruby calls to arbitrary C functions. Objective-C type signatures are used to specify argument and return types for all calls between Ruby and C. Arbitrary C functions are wrapped using instances of ObjC::Function.
- Many introspective features have been added to support debugging and performance analysis of the bridge itself.
Child modules and classes
Class ObjC::Class
Class ObjC::Function
Class ObjC::Method
Class ObjC::NSArray
Class ObjC::NSDictionary
Class ObjC::NSObject
Class ObjC::Object
Class ObjC::Variable
Constants
| Name | Value | Description | ||
|---|---|---|---|---|
| Ready | Qtrue | |||
Public Class methods
add_constant (p1, p2)
Add a symbolic constant to the ObjC module by importing the value corresponding to the specified symbol p1 and type p2. This method is typically used to wrap code that is not written in Objective-C.
add_enum (p1, p2)
Add an integer constant to the ObjC module with the specified name p1 and value p2. This method is typically used to wrap code that is not written in Objective-C.
add_function (p1)
Add an ObjC::Function p1 to the ObjC module as a module function. The module function will have the same name as the ObjC::Function. This method is typically used to wrap code that is not written in Objective-C.
external_resource_path ()
Get the path to the directory that contains the application (Cocoa-specific). This method is typically called from a Cocoa application‘s main.rb file.
get_methods ()
Get a hash containing the methods currently known to the Objective-C runtime. This method exhaustively scans the classes and methods in the Objective-C runtime and is surprisingly fast.
get_signature_for_selector (selector)
Get the signature for a given selector from the Objective-C runtime.
get_signatures ()
Get a hash containing the method signatures currently known to the Objective-C runtime. This method exhaustively scans the classes and methods in the Objective-C runtime and is surprisingly fast.
import (*names)
Import an Objective-C class for use in Ruby code. In most cases, this is done automatically. A NameError is raised if no corresponding Objective-C class can be found.
internal_resource_path ()
Get the path to an application‘s internal Resource directory (Cocoa-specific). This method is typically called from a Cocoa application‘s main.rb file.
load_all_files (path, except_this_file=nil)
Load all files in the specified directory (Cocoa-specific). This method is typically called from a Cocoa application‘s main.rb file.
load_internal_files (except_this_file="main.rb")
Load all Ruby files in the application directory, with the exception of the specified file (typically main.rb).
objc_method_calls ()
When Objective-C method call tracking is enabled, this returns a hash containing ObjC::Method objects as keys and the number of times each method has been called from Ruby since tracking was enabled.
objc_method_tracking= (p1)
Control tracking of Objective-C method calls. Set to true to enable tracking.
require (...)
Load one or more built-in RubyObjC components. Possible values include Foundation, AppKit, console, menu, nibtools. This method is typically called from a Cocoa application‘s main.rb file to load optional components. Component names can be given as Ruby strings or symbols and are case-insensitive.
set_path (p1)
Set the Ruby search path to be used by the application. Possible values are :LOCAL (to use the search path of the locally-installed ruby), :INTERNAL (to limit the search to the application‘s Resource directory), or a Ruby array of path names to use as the search path. This should be called at the beginning of any RubyObjC Cocoa application; it should typically be the first statement in the application‘s main.rb file.
strict= (strict)
Controls the enforcement of imethod/cmethod semantics. When true, the ObjC::Object method_added callback is disabled and methods are not automatically added to the Objective-C runtime. Instead, they must be declared with imethod (for instance methods) or cmethod (for class methods). When false, method_added attempts to expose all new methods to Objective-C. The default value is true.
top_methods (n = 10)
Get the n Objective-C methods that have been most frequently called from Ruby. Returns a list of lists. Each inner list contains the number of calls, the method, and the method signature. Objective-C method call tracking must be enabled.
top_signatures (n = 10)
Get the n Objective-C method signatures that have been most frequently called from Ruby. Returns a list of lists. Each inner list contains the number of calls and the method signature. Objective-C method call tracking must be enabled.
verbose= (p1)
Control the verbosity of the ObjC module. Set p1 to non-nil to generate logging messages.