1. 如何在rails console 里面调试 helpers 里的功能
[1] pry(main)> include=> Object
[2] pry(main)> include ActionView::Helpers=> Object[3]
pry(main)> text_field(:post, :title)=> "
"[4] pry(main)>
2. 在Ruby的开发中,随着程序版本的升级,有些旧的函数可能不再使用,那么如何通知你的用户了?
class Foo
# DEPRECATED: Please use useful instead.
def useless
warn "[DEPRECATION] `useless` is deprecated.
Please use `useful` instead." useful end def useful # ... endend3. 如何使你的class函数私有化如果你这么写的话,你所定义的函数仍然是public的状态class Foo private def self.bar endend为了让你的函数私有化,现在有两种写法1). class Foo def self.bar end private_class_method :barend2.) class Foo class << self private def bar end endend4. 定义class 函数的几种办法class Blog def self.foo puts 'I am a class method' end def Blog.bar puts 'I am a class method, too' end class << self def foobar puts 'I am another class method' end endend