Skip to content

Instantly share code, notes, and snippets.

@statonjr
Created June 11, 2010 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statonjr/434629 to your computer and use it in GitHub Desktop.
Save statonjr/434629 to your computer and use it in GitHub Desktop.
#!/usr/bin/macruby
# Need the AddressBook framework
framework 'AddressBook'
# Singleton
ab = ABAddressBook.sharedAddressBook
# me is the ABRecord of the current logged in user
# valueForProperty() is the KVO method to get the constant
# note the uppercase K. In Obj-C, the property is kABCreationDateProperty
creation_date = ab.me.valueForProperty(KABCreationDateProperty) # => NSDate object
# NSDate objects are not converted to Ruby Date objects
# Obj-C uses formatters to create strings from dates
date_formatter = NSDateFormatter.alloc.init
# Another constant
date_formatter.setDateStyle(NSDateFormatterMediumStyle)
# Here's our string
creation_date_string = date_formatter.stringFromDate(creation_date)
puts creation_date_string # => 'Jun 11, 2010'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment