Method: CF::Array.immutable

Defined in:
lib/corefoundation/array.rb

.immutable(array) ⇒ CF::Array

Creates a new, immutable CFArray from a ruby array of cf objects

Parameters:

  • array (Array<CF::Base>)

    The objects to place in the array. They must inherit from CF::Base

Returns:

  • (CF::Array)

    A CF::Array containing the objects, setup to release the array upon garbage collection



61
62
63
64
65
66
67
68
# File 'lib/corefoundation/array.rb', line 61

def self.immutable(array)
  if bad_element = array.detect {|value| !value.is_a?(CF::Base)}
    raise TypeError, "Array contains non cftype #{bad_element.inspect}" 
  end
  m = FFI::MemoryPointer.new(:pointer, array.length)
  m.write_array_of_pointer(array)
  new(CF.CFArrayCreate(nil,m,array.length,CF::kCFTypeArrayCallBacks.to_ptr))
end