Class: ObjC::Object

ObjC::Object wraps Objective-C objects for manipulation from Ruby.

ObjC::Object is the root class for a tree of Ruby classes. Subclasses are automatically generated on demand to match the Objective-C class hierarchy. There is a one-to-one mapping between the Ruby classes of wrapper objects and the Objective-C classes of the objects being wrapped.

Objective-C classes are also represented by instances of the Ruby class ObjC::Class, which provides Ruby access to class information maintained in the Objective-C runtime.


Public Class methods

cmethod (name, signature = nil, &block)

Declare a class method that is accessible from Objective-C. This is the preferred way to write Ruby methods that are to be added as class methods of Objective-C classes. Method signatures may be optionally specified. For example, the following adds an initialize method to an application delegate class:

     class ApplicationDelegate < ObjC::NSObject
       cmethod "initialize", "v@:" do
           ....
       end
     end

In this case, the "initialize" method is known to the Objective-C runtime and its signature can be safely omitted.

cmethods ()

Get the class methods defined for the underlying Objective-C class. Returns an array of objects of type ObjC::Method.

each_object (...)

Iterate over the entries in the bridge‘s internal table of wrapped objects. The table exists to ensure that any Objective-C object has at most one Ruby wrapper. If an optional class (derived from ObjC::Object) is specified, only objects of that class or its children are returned.

imethod (name, signature = nil, &block)

Declare an instance method that is accessible from Objective-C. This is the preferred way to write Ruby methods that are to be added as instance methods of Objective-C classes. Method signatures may be optionally specified. For example, the following adds a simple instance method to an application delegate class:

     class ApplicationDelegate < ObjC::NSObject
       imethod "applicationDidFinishLaunching:", "v@:@" do |sender|
          ...
       end
     end

In this case, the "applicationDidFinishLaunching:" method is not known to the Objective-C runtime, but because it resembles an action, its signature will be assumed to be "v@:@" and can be safely omitted.

imethods ()

Get the instance methods defined for the underlying Objective-C class. Returns an array of objects of type ObjC::Method.

ivars ()

Get the instance variables defined for the underlying Objective-C class. Returns an array of objects of type ObjC::Variable.

objc_accessor (*names)

Declare accessor functions for the specified names that make them available from Objective-C. This will allow these names to be used as outlets in Interface Builder. It also makes them observable using Key Value Observing. Values will be bridged to appropriate subclasses of NSObject.

object_count ()

Get the number of entries in the bridge‘s internal table of wrapped objects. The table exists to ensure that any Objective-C object has at most one Ruby wrapper.

Public Instance methods

<=> (p1)

Compare the object with another object p1.

== (p1)

Test object for equality with another object p1.

cmethods ()

Get the class methods defined for the underlying Objective-C class. Returns an array of objects of type ObjC::Method.

eql? (p1)

Test object for equality with another object p1.

forward (p1, p2)

Attempt to forward the specified selector p1 with the given array of arguments p2. Raise an exception if the forwarding fails.

get_cmethod (p1)

Lookup a class method of the corresponding Objective-C object by name p1.

get_imethod (p1)

Lookup an instance method of the corresponding Objective-C object by name p1.

hash ()

Get a hash value for an object.

imethods ()

Get the instance methods defined for the underlying Objective-C class. Returns an array of objects of type ObjC::Method.

inspect ()

Get a string description of the object.

invoke (p1, p2)

Attempt to invoke the specified selector p1 with the given array of arguments p2. Raise an exception if the invocation fails.

ivar (name)

Get the value of a named instance variable, if one exists. The name can be given as a Ruby string or symbol.

ivars ()

Get the instance variables defined for the underlying Objective-C class. Returns an array of objects of type ObjC::Variable.

method_missing (method, *args)

This method is automatically called when an unknown message is sent to an ObjC::Object instance. It attempts to convert the message into an invocation and then tries to forward the invocation to the underlying Objective-C object. If it fails, a NoMethodError exception is raised.

superclass ()

Get the superclass of the class of an object.

to_f ()

Get a floating-point representation of the object, if possible. Otherwise, return zero.

to_i ()

Get an integer representation of the object, if possible. Otherwise, return zero.

to_s ()

Get a string representation of the object. If the object responds to the bytes and length methods (eg. NSData), they are used to create the string. If the object responds to the cStringUsingEncoding method (eg. NSString), it is used to create the string. If the object responds to the stringValue method (eg. NSControl, NSNumber), it is used to create the string. Otherwise, this representation is identical to the one produced by the inspect method.