Ruby元编程的一些值得注意的地方
(编辑:jimmy 日期: 2025/5/18 浏览:3 次 )
避免无限循环的元编程。
写一个函数库时不要使核心类混乱(不要使用 monkey patch)。
代码块形式最好用于字符串插值形式。
当你使用字符串插值形式,总是提供 __FILE__ 和 __LINE__,使得你的回溯有意义。
class_eval 'def use_relative_model_naming"htmlcode"># from activesupport/lib/active_support/core_ext/string/output_safety.rb UNSAFE_STRING_METHODS.each do |unsafe_method| if 'String'.respond_to"htmlcode"># bad def method_missing?(meth, *args, &block) if /^find_by_(?<prop>.*)/ =~ meth # ... lots of code to do a find_by else super end end # good def method_missing?(meth, *args, &block) if /^find_by_(?<prop>.*)/ =~ meth find_by(prop, *args, &block) else super end end # best of all, though, would to define_method as each findable attribute is declared
下一篇:Ruby编程中的语法使用风格推荐
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。