程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> generator-ruby根據模板生成文件使用什麼gem?

generator-ruby根據模板生成文件使用什麼gem?

編輯:編程綜合問答
ruby根據模板生成文件使用什麼gem?

有一些重復的代碼 就是方法名 參數不一樣 想用ruby自動生成 請問用什麼gem呢?

--UPDATE--


-(void)doUpdateUserInfo:(NSDictionary *)params success:(YunposAPISuccess)success failure:(YunposAPIFailure)failure{
    [self postPath:@"" parameters:[self createParam:params action:@"doUpdateUserInfo" model:@"user"] success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
            success((AFJSONRequestOperation*)operation, responseObject);
        }
    } failure: ^(AFHTTPRequestOperation *operation, NSError *error){
        if (failure) {
            failure((AFJSONRequestOperation *)operation, error);
        }
    }];
}

類似這樣一個函數 我要寫好多次
但是 每個函數 會變的 只有函數名  然後[self postPath:@"" parameters:[self createParam:params action:@"doUpdateUserInfo" model:@"user"] 這裡面的參數

最佳回答:


ERB就可以了!
更簡單點用here doc然後gsub替換一下也行。
好像編輯器都有插入片段相同格式代碼的功能。

ERB就是類似這樣:

# tmp.erb
-(void)<%= function_name %>:(NSDictionary *)params success:(YunposAPISuccess)success failure:(YunposAPIFailure)failure{
    [self <%= path_name %>:@"" parameters:[self createParam:params action:@"doUpdateUserInfo" model:@"user"] success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
            success((AFJSONRequestOperation*)operation, responseObject);
        }
    } failure: ^(AFHTTPRequestOperation *operation, NSError *error){
        if (failure) {
            failure((AFJSONRequestOperation *)operation, error);
        }
    }];
}

然後根據傳來的變量生成你想要的結果..

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved