Ruby加载可选文件
示例
当文件不可用时,require家庭将抛出LoadError。此示例说明了仅在可选模块存在时加载它们。
module TidBits
@@unavailableModules = []
[
{ name: 'CoreExtend', file: 'core_extend/lib/core_extend' } \
, { name: 'Fs' , file: 'fs/lib/fs' } \
, { name: 'Options' , file: 'options/lib/options' } \
, { name: 'Susu' , file: 'susu/lib/susu' } \
].each do |lib|
begin
require_relative lib[ :file ]
rescue LoadError
@@unavailableModules.push lib
end
end
end #模块TidBits
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短