go top

使用单例类

网络释义

  Use the singleton-class

Ruby元编程技术详解Ruby Metaprogramming techniques ... 1. 使用单例类Use the singleton-class 当你想创建一个DSL来定义类信息时,最常见的问题是怎样表示信息来让框架的其它部分使用。以定义一个ActiveRecord模型对象为例: Q 这里令人感兴趣的是define_attr_method。在这个例子中我们需要获得Product类的单例类,但又不想修改ActiveRecord::Base。通过使用单例类我们达到了这个目的。我们为原来的方法取别名,再定义新的存取器(accessor)来返回值。如果ActiveRecord需要table 敶 name就可以直接调用存取器。这种动态创建方法和存取器的技术在单例类是很常见的,特别是Rails。 ...

基于2个网页-相关网页

有道翻译

使用单例类

Use singleton classes

以上为机器翻译结果,长、整句建议使用 人工翻译

双语例句

  • Jeremy认为大多数开发者没有正确使用Ruby对象所以话题比较高阶,谈论了诸如单例类(singleton classes)instance_eval。

    Jeremy believes that most programmers don't use Ruby's objects right, so his talk sheds some light onto advanced topics like singleton classes and the instance_eval.

    youdao

  • 这样分离结构代码有利于保持按单例模式使用或不按单例模式使用的灵活性。

    This has the added benefit of separating singleton code from the class code leaving the flexibility to use several instances of the class or using the class as a singleton.

    youdao

  • 3单例显然更为准确更为重要一点使用 PHPLSB 引用适当的覆盖静态

    The singleton in Listing 3 is certainly more concise, but what's important is the use of PHP's LSB to reference the appropriate overridden static attribute.

    youdao

更多双语例句
$firstVoiceSent
- 来自原声例句
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定