RubySugar 1.3.0

RubySugar 1.3.0

测试测试通过
语言编程语言 Obj-CObjective C
许可 MIT
发布最后一次发布2014年12月

Michal Konturek维护。



RubySugar 1.3.0

许可

该项目的源代码可在标准的MIT许可下获取。请参阅许可文件

简介

将Ruby语法糖移植到Objective-C。

id numbers = @[@0, @1, @2, @3, @4, @5];
id result = numbers[@"1..4"];
// [1, 2, 3, 4]

result = numbers[@"1...4"];
// 2, 3]

result = [@[@1, @2]:@[@3, @4]];
// [1, 2, 3, 4]

result = [@[@1, @2]:@3];
// [1, 2, 3]

[@3 rs_timesWithIndex:^(NSInteger index) {
    NSLog(@"Line #%i", index);
}];
// Line #0
// Line #1
// Line #2

result = @"Vexilla regis."[1];
// e

result = @"Vexilla regis."[@"1..6"];
// exilla

result = @"Vexilla regis."[@"1...6"];
// xill

result = [[[@"Number " :@10] :@" is greater than "] :@5];
// Number 10 is greater than 5.

result = [@"Hello" rs_chars];
// ["H", "e", "l", "l", "o"]

API

NSArray

- (instancetype):(id)object;

- (instancetype):(NSInteger)from :(NSInteger)to;
- (instancetype):(NSInteger)from :(NSInteger)to exclusive:(BOOL)exclusive;

- (instancetype)rs_clear;

- (instancetype)rs_combination:(NSInteger)n;

- (instancetype)rs_compact;

- (instancetype)rs_delete:(id)object;
- (instancetype)rs_deleteAt:(NSInteger)index;
- (id)rs_deleteIf:(BOOL(^)(id item))block;

- (instancetype)rs_drop:(NSInteger)count;
- (id)rs_dropWhile:(BOOL(^)(id item))block;

- (void)rs_each:(void (^)(id item))block;

- (id)rs_fetch:(NSUInteger)index;

- (instancetype)rs_fill:(id)object;
- (instancetype)rs_fill:(id)object withRange:(NSRange)range;

- (instancetype)rs_flatten;
- (instancetype)rs_flatten:(NSInteger)level;

- (BOOL)rs_includes:(id)object;

- (id)rs_inject:(id (^)(id accumulator, id item))block;
- (id)rs_inject:(id)initial withBlock:(id (^)(id accumulator, id item))block;

- (BOOL)rs_isEmpty;

- (NSString *)rs_join;
- (NSString *)rs_join:(NSString *)separator;

- (instancetype)rs_map:(id (^)(id item))block;

- (instancetype)rs_permutation;
- (instancetype)rs_permutation:(NSInteger)n;

- (instancetype)rs_reject:(BOOL (^)(id item))block;

- (instancetype)rs_reverse;

- (id)rs_sample;
- (instancetype)rs_sample:(NSUInteger)count;

- (instancetype)rs_select:(BOOL (^)(id item))block;

- (instancetype)rs_shuffle;

- (instancetype)rs_take:(NSInteger)count;
- (id)rs_takeWhile:(BOOL(^)(id item))block;

- (instancetype)rs_uniq;
- (instancetype)rs_uniq:(id(^)(id item))block;

- (instancetype)rs_zip;

- (id)objectForKeyedSubscript:(id<NSCopying>)key;

NSNumber

- (instancetype)rs_gcd:(NSInteger)other;

- (instancetype)rs_lcm:(NSInteger)other;

- (instancetype)rs_next;

- (instancetype)rs_pred;

- (id)rs_times:(void(^)(void))block;
- (id)rs_timesWithIndex:(void(^)(NSInteger index))block;

- (id)rs_downto:(NSInteger)limit do:(void(^)(NSInteger index))block;

- (id)rs_upto:(NSInteger)limit do:(void(^)(NSInteger index))block;

- (NSArray *)rs_numbersTo:(NSInteger)to;

NSString

- (NSString *):(id)object;

- (NSString *):(NSInteger)from :(NSInteger)to;
- (NSString *):(NSInteger)from :(NSInteger)to exclusive:(BOOL)exclusive;

- (NSArray *)rs_chars;

- (BOOL)rs_containsString:(NSString *)term;
- (BOOL)rs_containsString:(NSString *)term caseSensitive:(BOOL)caseSensitive;

- (NSString *)rs_delete:(id)input;

- (id)rs_eachChar:(void(^)(NSString *item))block;

- (BOOL)rs_isEmpty;

- (NSString *)rs_justifyLeft:(NSInteger)length;
- (NSString *)rs_justifyLeft:(NSInteger)length with:(NSString *)pad;

- (NSString *)rs_justifyRight:(NSInteger)length;
- (NSString *)rs_justifyRight:(NSInteger)length with:(NSString *)pad;

- (NSArray *)rs_split;
- (NSArray *)rs_split:(NSString *)pattern;

- (NSString *)rs_strip;

- (id)objectAtIndexedSubscript:(NSUInteger)index;
- (id)objectForKeyedSubscript:(id<NSCopying>)key;

贡献

  1. 克隆此存储库。
  2. 创建您的特性分支(git checkout -b new-feature)。
  3. 提交您的更改(git commit -am '添加新特性')。
  4. 将分支推送到远程仓库(git push origin new-feature)。
  5. 创建新的Pull Request。