What are the uppercase and lowercase rules of ruby method name?

后端 未结 2 953
春和景丽
春和景丽 2021-02-02 15:11

I am a Ruby beginner. From the book, I know that a Ruby method name should start with a lowercase letter or underscore. But I found different scenarios:

  1. If a me

2条回答
  •  终归单人心
    2021-02-02 15:38

    Don't do any of what you're trying to do. It's bad coding style.

    Good Ruby coding style:

    def method_name
    end
    
    # or
    
    class CamelCase
      def method_name(parameter_name)
      end
    end
    

    Almost anything else is simply wrong. The language might let you do other stuff, but that doesn't mean you should.

    Also, generally you don't want to be defining methods outside of a class or module — that's acceptable in short throw-away scripts, but not in projects of substance.

提交回复
热议问题