简体   繁体   中英

What's the proper style to indent Ruby on Rails code?

I've noticed that Ruby on Rails code has 2 spaces indentation, eg:

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      ...
      t.timestamps
    end
  end
  ...
end

Is this a convention to have 2 spaces ? (I've used to indent with Tab, which is usually 4 spaces.)

Bonus: Does anyone know how to change the Tab size from 4 spaces to 2 spaces in e text editor?

是的,每个缩进级别两个空格是Ruby 社区标准

Yes, I always indent 2 spaces instead of tabs. It looks a little nicer.

Rails itself uses the same convention.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM