class SDL2::Point
Public Class Methods
cast(something)
click to toggle source
Calls superclass method
# File lib/sdl2/point.rb, line 10 def self.cast(something) if something.kind_of?(Array) and something.count == 2 something.map!(&:to_i) result = Point.new result.x, result.y = something return result else return super end end
cast_array(somethings, count_something = nil)
click to toggle source
# File lib/sdl2/point.rb, line 21 def self.cast_array(somethings, count_something = nil) # Convert Ruby arrays into Struct Arrays. if somethings.kind_of? Array count_something = somethings.count if count_something.nil? raise "count_something > somethings.count" if count_something > somethings.count pointer = FFI::MemoryPointer.new(self, count_something) count_something.times do |idx| pointer[idx].update_members(somethings[idx]) end somethings = pointer # If it is already a structure, then it is an array of 1, unless # someone defined a count, in which case we assume they know what they # are doing. elsif somethings.kind_of? self count_something = 1 if count_something.nil? else raise "#{self} cannot cast array from #{somethings.inspect}" end return somethings, count_something end