Skip to content

Instantly share code, notes, and snippets.

@charliemaffitt
Created October 26, 2012 21:09
Show Gist options
  • Save charliemaffitt/3961533 to your computer and use it in GitHub Desktop.
Save charliemaffitt/3961533 to your computer and use it in GitHub Desktop.
# File: MainView.m
[Doorman requestUnlockDoor:^(BOOL successfulRequest) {
if (successfulRequest) {
// do stuff
}
else {
// do other stuff
}
}];
# File: Doorman.m
@implementation Doorman
+ (void)requestUnlockDoor:(void(^)(BOOL successfulRequest))completionHandler {
completionHandler(FALSE);
}
@end
@alindeman
Copy link

1.9.3p286 :001 > completionHandler = proc { |successfulRequest| puts "successful request is #{successfulRequest}" }
 => #<Proc:0x007f8c3b843950@(irb):1>
1.9.3p286 :002 > completionHandler.(true)
successful request is true
 => nil
1.9.3p286 :003 > completionHandler.(false)
successful request is false
 => nil

@charliemaffitt
Copy link
Author

class Doorman
  def self.open_door(&block)
      block.call true #or false
end

Doorman.open_door do |success|
  if success
    puts "success"
  else
    puts "failure"
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment