Руководство по стилю программирования на Руби

Ruby Community, “ruby-style-guide”, public translation into Russian from English More about this translation.

See also 26 similar translations

Translate into another language.

Participants

flipback1316 points
jefir2 points
Join Translated.by to translate! If you already have a Translated.by account, please sign in.
If you do not want to register an account, you can sign in with OpenID.
Pages: ← previous Ctrl next next untranslated
1 2 3 4 5 6

ruby-style-guide

Руководство по стилю программирования на Руби

History of edits (Latest: flipback 8 months, 1 week ago) §

# Abstract

# Предисловие

History of edits (Latest: flipback 8 months, 1 week ago) §

... nearly everybody is convinced that every style but their own is
ugly and unreadable. Leave out the "but their own" and they're
probably right...
--Jerry Coffin (on indentation)

... почти каждый убеждён, что чужой код уродливый и нечитаемые. За исключением "его собственного" и они возможно правы...
-- Джери Соффин (в отступлении)

History of edits (Latest: flipback 8 months, 1 week ago) §

This document was created when I, as the Technical Lead of the company
in which I work for, was asked by the CTO to create some internal documents
describing good style and best practices for Ruby programming. I started off
by building upon
[this existing style guide](https://github.com/chneukirchen/styleguide),
since I concurred with most of the points in it. I hope it will be useful to
other people as well and I hope that I'll get a lot of feedback and
suggestions on how to improve the guide for the benefit of the entire Ruby
community.

Этот документ был создан, когда я как работник технического сопровождения компании в которой я работал, спросил технического директора создать какой нибудь внутренний документ описывающий хороший стиль и лучшие практики программирования Руби. Я начал взяв за основу [этот труд](https://github.com/chneukirchen/styleguide), так как я согласен с большей частью его. Я надеюсь, что руководство будет полезно другим людям и, что я получу отзывы и предложения по улучшению его во благо всего Руби сообщества.

History of edits (Latest: flipback 8 months, 1 week ago) §

## Formatting

## Форматирование

History of edits (Latest: jefir 3 months ago) §

* Use UTF-8 as the source file encoding.
* Use two space indent, no tabs. (Your editor/IDE should have a setting to
help you with that.)
* Use Unix-style line endings. (Linux/OSX users are covered by default,
Windows users have to be extra careful.)
* If you're using Git you might want to do `$ git config --global
core.autocrlf true` to protect your project from Windows line endings
creeping into your project.
* Use spaces around operators, after commas, colons and semicolons, around {
and before }.

* Используйте UTF-8 как кодировку исходных файлов.
* Используйте два пробела, а не табуляцию. (Ваш редактор/IDE должна иметь опцию Вам в помощь.)
* Используйте Unix-стиль завершения строк. (Linux/OSX пользователи прикрыты по умолчанию, Windows пользователям необходимо быть более осторожным.)
* Если Вы используете Git Вы можете сделать `$ git config --global
core.autocrlf true` для защиты Вашего проект от Windows завершения строк ползущих по проекту.
* Используйте пробелы вокруг операторов, после запятых и фигурных скобок { и после }.

History of edits (Latest: flipback 8 months, 1 week ago) §

```Ruby
sum = 1 + 2
a, b = 1, 2
1 > 2 ? true : false; puts "Hi"
[1, 2, 3].each { |e| puts e }
```

```Ruby
sum = 1 + 2
a, b = 1, 2
1 > 2 ? true : false; puts "Hi"
[1, 2, 3].each { |e| puts e }
```

History of edits (Latest: flipback 8 months, 1 week ago) §

* No spaces after (, [ or before ], ).

* Без пробелов после (, [ или перед ],).

History of edits (Latest: flipback 8 months, 1 week ago) §

```Ruby
some(arg).other
[1, 2, 3].length
```

```Ruby
some(arg).other
[1, 2, 3].length
```

History of edits (Latest: flipback 8 months, 1 week ago) §

* Indent **when** as deep as **case**. (As suggested in the Pickaxe.)

* Отступ **when** на том же уровне что и **case**. (Как предлагается в Pickaxe.)

History of edits (Latest: flipback 8 months, 1 week ago) §

```Ruby
case
when song.name == "Misty"
puts "Not again!" when song.duration > 120
puts "Too long!" when Time.now.hour > 21
puts "It's too late"
else
song.play
end

```Ruby
case
when song.name == "Misty"
puts "Not again!" when song.duration > 120
puts "Too long!" when Time.now.hour > 21
puts "It's too late"
else
song.play
end

History of edits (Latest: flipback 8 months, 1 week ago) §

kind = case year
when 1850..1889 then "Blues"
when 1890..1909 then "Ragtime"
when 1910..1929 then "New Orleans Jazz" when 1930..1939 then "Swing"
when 1940..1950 then "Bebop"
else "Jazz"
end
```

kind = case year
when 1850..1889 then "Blues"
when 1890..1909 then "Ragtime"
when 1910..1929 then "New Orleans Jazz"
when 1930..1939 then "Swing"
when 1940..1950 then "Bebop"
else "Jazz"
end
```

History of edits (Latest: flipback 8 months, 1 week ago) §
Pages: ← previous Ctrl next next untranslated
1 2 3 4 5 6