开发者

Require statements inside methods?

I am working on developing an API for a test suite. One of the methods in the API requires the use of a library that isn't needed anywhere else in the API.

My question is whether the require statement for using the library s开发者_Go百科hould be placed inside the method or every time the API loads. The library isn't very large so it won't have a significant effect on performance.


If the dependency has good namespace organization (won't pollute the global namespace) and isn't large (won't slow startup times), I'd say put it at the top of the file. It's where people expect to find require statements. If it has either of those problems, consider putting it in the most limited scope possible.


I'd prefer putting the 'require' statement near the top of the file because when looking in the .rb it makes the dependencies clear. Similar to how .c files normally have all the #includes at the top.


i will use require statement in method even if the file is small....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜