This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car | |
include RequireOptions | |
def go(opts) | |
gear, speed = require_options(opts, :speed, :gear) | |
# ... | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation ConfirmationAlert | |
+ (void)show:(NSString *)message delegate:(id<UIAlertViewDelegate>)theDelegate { | |
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Confirm" message:message delegate:theDelegate cancelButtonTitle:@"Cancel" otherButtonTitles:@"Confirm", nil] autorelease]; | |
[alertView show]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation MyObject | |
-(void)showOneConfirmationAlert:(NSMutableDictionary *)externalState { | |
externalStateForOneConfirmationAlert = [externalState retain]; | |
oneConfirmationAlert = [[ConfirmationAlert show:@"Are you sure about this?" delegate:self] retain]; | |
} | |
-(void)showAnotherConfirmationAlert:(NSMutableDictionary *)externalState { | |
externalStateForAnotherConfirmationAlert = [externalState retain]; | |
oneConfirmationAlert = [[ConfirmationAlert show:@"Again, are you sure?" delegate:self] retain]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef void (^ConfirmationBlock)(UIAlertView *); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (void)show:(NSString *)message confirmed:(ConfirmationBlock)confirmBlock canceled:(ConfirmationBlock)canceledBlock { | |
if(blocks == nil) { | |
blocks = [[NSMutableDictionary dictionary] retain]; | |
delegate = [[BlockConfirmationAlert alloc] init]; | |
} | |
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Confirm" message:message delegate:delegate cancelButtonTitle:@"Cancel" otherButtonTitles:@"Confirm", nil] autorelease]; | |
NSDictionary *blockDict = [NSDictionary dictionaryWithObjectsAndKeys:[[confirmBlock copy] autorelease], @"confirm", [[canceledBlock copy] autorelease], @"cancel", nil]; | |
[blocks setObject:blockDict forKey:[NSNumber numberWithUnsignedInt:[alertView hash]]]; | |
[alertView show]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (void)showOneConfirmationAlert:(NSMutableDictionary *)externalState { | |
[BlockConfirmationAlert show:@"Are you sure about this?" | |
confirmed:^(UIAlertView *alertView) { | |
//... | |
NSLog([externalState objectForKey:@"Key"]); | |
} | |
canceled:^(UIAlertView *alertView) { | |
//... | |
NSLog([externalState objectForKey:@"DifferentKey"]); | |
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSInvocation *invocation; | |
//set it up | |
@try { | |
objc_msgSend(obj, [invocation selector]); | |
} | |
@catch (NSException * e) { | |
NSLog(@"Caught exception: %@", e); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSInvocation *invocation; | |
// Create it | |
[invocation setTarget:obj]; | |
[invocation setSelector:@selector(myMethod)]; | |
@try { | |
[invocation invoke]; | |
} | |
@catch (NSException * e) { | |
NSLog(@"This exception cannot be caught"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SHKItem *item = [[[SHKItem alloc] init] autorelease]; | |
item.shareType = SHKShareTypeText; | |
item.contextBlock = ^(NSString *selectedSharer, id item) { | |
if ([selectedSharer isEqualToString:@"SHKTwitter"]) { | |
[item setShareType:SHKShareTypeURL]; | |
[item setURL:[NSURL URLWithString:@"http://www.google.com"]]; | |
[item setTitle:@"Tweeting this! #HashTagsAreCoolForKids"]; | |
} else { | |
[item setMessage:@"This is for everything else http://www.google.com"]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (state == MotionState.DRAGGING) { | |
bottomCaliperMatrix.set(bottomCaliperSavedMatrix); | |
float yoffset = motionEvent.getY() - startPoint.y; | |
bottomCaliperMatrix.postTranslate(0, yoffset); | |
float[] bottomMatrix = new float[9]; | |
bottomCaliperMatrix.getValues(bottomMatrix); | |
float delta = Math.abs(Math.min(bottomMatrix[5] - 79, 0)); | |
bottomCaliperMatrix.postTranslate(0, delta); | |
} |
OlderNewer