Last active
August 29, 2015 14:01
-
-
Save WA9ACE/c4ea6c9e165e7271ff86 to your computer and use it in GitHub Desktop.
Objective-C with comments to point out semantic syntax differences with Ruby : Part 1
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
// | |
// ICEBrain.h | |
// | |
#import <Foundation/Foundation.h> | |
@interface ICEBrain : NSObject | |
@property (nonatomic) NSString *someProperty; | |
- (NSString *)processMessage:(NSString *)message; | |
- (void)takeFirstParam:(NSString *)first andSecond:(NSString *)second; | |
+ (NSString *)think; | |
@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
// | |
// ICEBrain.m | |
// | |
#import "ICEBrain.h" | |
@implementation ICEBrain | |
// def processMessage(message) | |
- (NSString *)processMessage:(NSString *)message | |
{ | |
return message; | |
} | |
// def takeFirstParam:andSecond:(first, second) | |
- (void)takeFirstParam:(NSString *)first andSecond:(NSString *)second | |
{ | |
NSLog(@"First: %@\nSecond: %@", first, second); | |
} | |
// def self.think | |
+ (NSString *)think | |
{ | |
return @"I'm thinking..."; | |
} | |
@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
// | |
// main.m | |
// | |
#import <Foundation/Foundation.h> | |
#import "ICEBrain.h" | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
// ICEBrain::think | |
[ICEBrain think]; | |
// brain = ICEBrain.new | |
ICEBrain *brain = [[ICEBrain alloc] init]; | |
// result = brain.processMessage("Hello World") | |
NSString *result = [brain processMessage:@"Hello World"]; | |
// brain.takeFirstParamandSecond("first", "second") | |
[brain takeFirstParam:@"first" andSecond:@"second"]; | |
// brain.someProperty = "something" with :attr_accessor | |
brain.someProperty = @"This is now set to this string."; | |
brain.someProperty // without assignment returns "This is now set to this string." | |
NSLog(@"%@", result); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment