twinslash / cookbook

Knowledge base with guides, articles about good practices and programming recipes
8 stars 5 forks source link

Private methods indentation #10

Open dzhlobo opened 11 years ago

dzhlobo commented 11 years ago

We should discuss code convention about indentation private methods in classes. We have two common conventions.

First one:

class Foo
  def public_method
  end

  private

    def private_method
    end
end

Second one:

class Bar
  def public_method
  end

private

  def private_method
  end
end

Also I propose to add one blank line before private word and one after.

dzhlobo commented 11 years ago

@gotva, @FoboCasteR, @jaturken what do you think about this?

I personally prefer second variant but have no arguments.

FoboCasteR commented 11 years ago

https://github.com/bbatsov/ruby-style-guide/issues/31

gotva commented 11 years ago

I prefer

class Foo
  class << self
    def method_of_class
    end
  end

  def instance_method
  end

  private # or protected

    def private_method
    end

end

I prefer to have more than 2 spaces in any not public-instance methods. When you open a model with 100+ lines you go to the end of file and start writing code it can be wrong place for your code (it can be private/protected section). If you have convention described above you will see 4 spaces before definition and it is a sign that it is not correct place for your code

FoboCasteR commented 11 years ago

https://github.com/bbatsov/ruby-style-guide#classes--modules

jaturken commented 11 years ago

@FoboCasteR :+1: