Skip to content

Instantly share code, notes, and snippets.

@jslabovitz
Created July 19, 2012 19:39
Show Gist options
  • Save jslabovitz/3146276 to your computer and use it in GitHub Desktop.
Save jslabovitz/3146276 to your computer and use it in GitHub Desktop.
MacRuby/RubyMotion 'Enum' class & sample code
#!/usr/bin/env macruby
class Enum
def initialize(value)
@value = value
end
def pointer
ptr = Pointer.new(type)
ptr[0] = @value
ptr
end
def size
size_ptr = Pointer.new('Q')
align_ptr = Pointer.new('Q')
NSGetSizeAndAlignment(type, size_ptr, align_ptr)
size_ptr.value
end
end
class CTTextAlignment < Enum
def type
'C'
end
end
# sample code to test above classes
framework 'ApplicationServices'
alignment = CTTextAlignment.new(KCTCenterTextAlignment)
setting = CTParagraphStyleSetting.new(KCTParagraphStyleSpecifierAlignment, alignment.size, alignment.pointer)
settingsPtr = Pointer.new(CTParagraphStyleSetting.type)
settingsPtr[0] = setting
paragraphRef = CTParagraphStyleCreate(settingsPtr, 1)
p paragraphRef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment