Для iOS7 заменить:
CGSize size = [tempPointStr sizeWithFont:self.lblHidden.font
constrainedToSize:self.lblHidden.frame.size
lineBreakMode:NSLineBreakByWordWrapping];
на:
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping; //set the line break mode
NSDictionary *attrDict = [NSDictionary dictionaryWithObjectsAndKeys:self.lblHidden.font, NSFontAttributeName, paragraphStyle, NSParagraphStyleAttributeName, nil];
CGSize size = [tempPointStr boundingRectWithSize:self.lblHidden.frame.size
options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
attributes:attrDict context:nil].size;
Вы можете поместить их в каталог / lib, и они будут загружены вместе с вашим проектом Rails.
Например, вы можете просмотреть это мое репо старого проекта: lib каталог проекта Rails
Так, например, у меня есть следующий модуль:
google_charts.rb
Module GCharts
class GoogleCharts
def some_method
end
end
end
И где угодно в моем приложении Rails я могу получить доступ к методам.
Итак, если бы я получил доступ к нему с контроллера, я бы просто сделал:
require 'google_charts'
GCharts::GoogleCharts.some_method
1) Any time I'm about to duplicate (or substantially duplicate) a piece of code: "oh, i could just cut/paste into this other controller . . . "
2) Any time I write code that is very obviously going to be reused in the future.
3) Code of substantial size that has a specific purpose, where that purpose is fairly distinct from the main purpose of the controller/model. This is somewhat related to (2), but sometimes code won't get reused but a module helps for organization.
Мы используем модули для функций, которые не привязаны к моделям ActiveRecord и не были абстрагированы в плагин или гем.
Недавний пример из нашей производственной базы кода - это библиотека для интеграции с Campaign Monitor для управления списком рассылки. Ядро системы использует нашу пользовательскую модель, но фактическое взаимодействие со службой extenrl абстрагируется через модуль, который находится в /lib.