Why are methods in Ruby documentation preceded by a hash sign?

前端 未结 8 785
小蘑菇
小蘑菇 2020-11-30 21:05

When I see any Ruby method printed in text, it usually appears as:

Class#method

or

#method

Now, I would u

8条回答
  •  一个人的身影
    2020-11-30 21:41

    All the answers above you list are correct. The one thing I would add is that the documentation style you said you would perfer

    Class.method

    would be easily confused with class methods. Since you can call class methods in ruby using the above syntax:

    class Foo
      def self.say_hi
        puts "hi"
      end
    end
    
    Foo.say_hi    # => prints "hi"
    

提交回复
热议问题