Method: FFI::Pointer#write_type

Defined in:
lib/ffi_pointer.rb

#write_type(type, value) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
# File 'lib/ffi_pointer.rb', line 14

def write_type(type, value)
	type = FFI.find_type(type) if type.is_a?(Symbol)
	type = type.native_type if type.is_a?(FFI::Type::Mapped)
	raise ArgumentError, "Can only write built-in types (type=#{type})" unless type.is_a?(FFI::Type::Builtin)
	name = type.inspect.match(/<#{type.class}:(\S+)/)[1].downcase
	method = "write_#{name}".to_sym
	self.send(method, value)
end