Class List Method List File List

# Class: OSX::ObjcID

Inherits:
  Object
  - Object
  - OSX::ObjcID
  show all
Defined in:
  src/objc/cls_objcid.m,
  src/objc/cls_objcid.m

## Overview

Root class of Objective-C classes in Ruby world.

Examples:

    OSX::NSObject.superclass
    => OSX::ObjcID
    OSX::NSProxy.superclass
    => OSX::ObjcID
    OSX::NSString.superclass
    => OSX::NSObject

## Class Method Summary (collapse)

- + (Object) new_with_ocid private

## Instance Method Summary (collapse)

- - (String) __inspect__

  Object#inspect.

- - (Number) __ocid__

  Objective-C id value as Number.

- - (Boolean) eql? (also: #==)

  Returns `true` when `other` contains same Objective-C "id".

- - (FIXNUM) hash

  Returns an hash value form internal Objective-C "id".

- - (Object) initialize_copy private

  Returns shallow copied object by Object#dup.

- - (String) inspect

  Object#inspect.

- - (Object) release

  Sends Objective-C "release" message to reciever.

## Class Method Details

### + (`Object`) new_with_ocid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

    85
    86
    87
    88
    89

    # File 'src/objc/cls_objcid.m', line 85

    static VALUE
    wrapper_objcid_s_new_with_ocid(VALUE klass, VALUE rbocid)
    {
      return objcid_new_with_ocid(klass, NUM2OCID(rbocid));
    }

## Instance Method Details

### - (`String`) __inspect__

Note:

overrides Object#inspect.

Object#inspect.

Returns:

- (`String`)

    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165

    # File 'src/objc/cls_objcid.m', line 136

    static VALUE
    objcid_inspect(VALUE rcv)
    {
      char              s[512];
      id                ocid;
      struct bsConst *  bs_const;
      const char *      class_desc;
      id                pool;

      ocid = OBJCID_ID(rcv);
      bs_const = find_magic_cookie_const_by_value(ocid);
      if (bs_const != NULL) {
        pool = nil;
        class_desc = bs_const->class_name;
      }
      else {
        pool = [[NSAutoreleasePool alloc] init];
        class_desc = [[[ocid class] description] UTF8String];
      }

      snprintf(s, sizeof(s), "#<%s:0x%lx class='%s' id=%p>",
        rb_class2name(CLASS_OF(rcv)),
        NUM2ULONG(rb_obj_id(rcv)),
        class_desc, ocid);

      if (pool != nil)
        [pool release];

      return rb_str_new2(s);
    }

### - (`Number`) __ocid__

Objective-C id value as Number.

Examples:

    url = OSX::NSURL.URLWithString('http://www.apple.com')
    url.inspect
    => "#<OSX::NSURL:0x8775b0c0 class='NSURL' id=0x7fe3b2913690>"
    url.__ocid__
    => 140615930164880

Returns:

- (`Number`)

    125
    126
    127
    128
    129

    # File 'src/objc/cls_objcid.m', line 125

    static VALUE
    objcid_ocid(VALUE rcv)
    {
      return OCID2NUM(OBJCID_ID(rcv));
    }

### - (`Boolean`) eql? Also known as: ==

Note:

overrides Object#eql? and Object#==.

Returns `true` when `other` contains same Objective-C "id".

Examples:

    num1 = OSX::NSNumberWithInt(1)
    num2 = OSX::NSNumberWithInt(1)
    num1.eql?(num2)
    # => true
    num1 == num2
    # => true
    num1.__id__ == num2.__id__
    # => false
    num1.__ocid__ == num2.__ocid__
    # => true

Returns:

- (`Boolean`)

    203
    204
    205
    206
    207
    208
    209
    210

    # File 'src/objc/cls_objcid.m', line 203

    static VALUE
    objcid_eql(VALUE rcv, VALUE other)
    {
      if (rb_obj_is_kind_of(other, _kObjcID) && OBJCID_ID(rcv) == OBJCID_ID(other)) {
        return Qtrue;
      }
      return Qfalse;
    }

### - (`FIXNUM`) hash

Note:

overrides Object#hash.

Returns an hash value form internal Objective-C "id".

Examples:

    num1 = OSX::NSNumberWithInt(1)
    num2 = OSX::NSNumberWithInt(1)
    num1.__id__ == num2.__id__
    # => false
    num1.hash == num2.hash
    # => true

Returns:

- (`FIXNUM`)

    179
    180
    181
    182
    183
    184
    185
    186

    # File 'src/objc/cls_objcid.m', line 179

    static VALUE
    objcid_hash(VALUE rcv)
    {
      id ocid;

      ocid = OBJCID_ID(rcv);
      return LONG2FIX(ocid);
    }

### - (`Object`) initialize_copy

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns shallow copied object by Object#dup.

    108
    109
    110
    111
    112
    113

    # File 'src/objc/cls_objcid.m', line 108

    static VALUE
    objcid_init_copy(VALUE self, VALUE orig)
    {
      OBJCID_DATA_PTR(self)->ocid = OBJCID_DATA_PTR(orig)->ocid;
      return self;
    }

### - (`String`) inspect

Note:

overrides Object#inspect.

Object#inspect.

Returns:

- (`String`)

    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165

    # File 'src/objc/cls_objcid.m', line 136

    static VALUE
    objcid_inspect(VALUE rcv)
    {
      char              s[512];
      id                ocid;
      struct bsConst *  bs_const;
      const char *      class_desc;
      id                pool;

      ocid = OBJCID_ID(rcv);
      bs_const = find_magic_cookie_const_by_value(ocid);
      if (bs_const != NULL) {
        pool = nil;
        class_desc = bs_const->class_name;
      }
      else {
        pool = [[NSAutoreleasePool alloc] init];
        class_desc = [[[ocid class] description] UTF8String];
      }

      snprintf(s, sizeof(s), "#<%s:0x%lx class='%s' id=%p>",
        rb_class2name(CLASS_OF(rcv)),
        NUM2ULONG(rb_obj_id(rcv)),
        class_desc, ocid);

      if (pool != nil)
        [pool release];

      return rb_str_new2(s);
    }

### - (`Object`) release

Sends Objective-C "release" message to reciever.

    94
    95
    96
    97
    98
    99
    100
    101
    102

    # File 'src/objc/cls_objcid.m', line 94

    static VALUE
    objcid_release(VALUE rcv)
    {
      if (OBJCID_DATA_PTR(rcv)->can_be_released) {
        [OBJCID_ID(rcv) release];
        OBJCID_DATA_PTR(rcv)->can_be_released = NO;
      }
      return rcv;
    }