Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add translation of 06-Hashes #22

Merged
merged 5 commits into from
Aug 29, 2017
Merged

Add translation of 06-Hashes #22

merged 5 commits into from
Aug 29, 2017

Conversation

denysdovhan
Copy link
Member

Ref #8


While arrays provide a good way of indexing a collection of items by number, there may be times when it would be more convenient to index them in some other way. If, for example, you were creating a collection of recipes, it would be more meaningful to have each recipe indexed by name such as ‚Rich Chocolate Cake‛ and ‚Coq au Vin‛ rather than by numbers: 23, 87 and so on.
Масиви надають хороший спосіб індексації елементів колекції за числом, одна можуть бути випадки, коли набагато зручніше індексувати їх по іншому. Якщо, наприклад, ви створювали колекцію рецептів, було б набагато зрозуміліше індексувати рецепти за їхніми назвами, як от “Великий шоколадний торт” та “Coq au Vin”, а не 23, 87 і так далі.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Однак ..по-іншому(!)


Ruby has a class that lets you do just that. It’s called a Hash. This is the equivalent of what some other languages call a ‘Dictionary’. Just like a real dictionary, the entries are indexed by some unique key (in a dictionary, this would be a word) and a value (in a dictionary, this would be the definition of the word).
Ruby має клас, який дозволяє вам зробити це. Він називається `Hash` (хеш). Він еквівалентний до того, що у інших мовах називають _словником_. Як і справжній словник, елементи індексуються за деяким унікальним ключем (у словнику це може бути словом) та значенням (у словнику це визначення для певного слова).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У словнику -(!) це визначення


Ruby has a class that lets you do just that. It’s called a Hash. This is the equivalent of what some other languages call a ‘Dictionary’. Just like a real dictionary, the entries are indexed by some unique key (in a dictionary, this would be a word) and a value (in a dictionary, this would be the definition of the word).
Ruby має клас, який дозволяє вам зробити це. Він називається `Hash` (хеш). Він еквівалентний до того, що у інших мовах називають _словником_. Як і справжній словник, елементи індексуються за деяким унікальним ключем (у словнику це може бути словом) та значенням (у словнику це визначення для певного слова).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У словнику- це визначення


Having created a Hash object, you can add items to it using an array-like syntax – that is, by placing the index in square brackets and using `=` to assign a value.
Моючи створений `Hash`–об’єкт ви можете додавати у нього елементи використовуючи синтаксис схожий на масиви: вказуючи індекс між квадратними дужками та використовуючи `=` для присвоєння значення.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

об'єкт,(!) ви можете додавати у нього елементи,(!) використовуючи..

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у нього елементи,(!) використовуючи


The obvious difference here being that, with an array, the index (the ‘key’) must be an integer; with a Hash, it can be any unique data item:
Очевидна відмінність тут у тому, що для масивів індексом (_ключем_) має бути ціле число; для хешу це може бути будь-які унікальний елемент даних:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Будь-якИЙ

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

будь-яким унікальним елементом

@@ -31,14 +31,14 @@ h2['treasure3'] = 'Ruby ring'
h2['treasure4'] = 'Sapphire ring'
```

Often, the key may be a number or, as in the code above, a string. In principle, however, a key can be any type of object. Given some class, `X`, the following assignment is perfectly legal:
Часто, ключем може бути число або, як у прикладі вище, рядок. В принципі, ключем може бути об’єкт будь–якого типу. Маючи деякий клас, скажімо `X`, таке присвоєння є цілком можливим:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Часто (!) ключем може бути...


**`hash2.rb`**:

The `keys` and `values` methods of `Hash` each return an array so you can use various Array methods to manipulate them. Here are a few simple examples (note, the data shown in comments beginning `#=>` show the values returned when each piece of code is run):
Методи `keys` (ключі) та `values` (значення) для `Hash` повертають масиви, тож ви можете різні методи масивів, щоб маніпулювати ними. Ось кілька простих прикладів (зауважте, що значення, які отримаються в результаті запуску рядка коду показані у коментарях, що починаються з `#=>`):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можете використовувати різні методи масивів, ..

#=> ["KEY_TWO", "key4", "key3", "key1", "key4", "key3", "key2", "key1"]
```

Be careful to note the difference between concatenating using `+` to add the values from the second array to the first array and appending using `<<` to add the second array itself as the final element of the first array:
Зверніть особливу увагу на відмінність між конкатенацією з допомогою `+`, щоб додавати значення другого масиву до першого, та додаванням в кінець з допомогою `<<`, щод додавати цілий другий масив як останній елемент першого масиву:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

щоБ додавати цілий другий масив,(!) як останній елемент першого масиву.

@@ -126,7 +125,7 @@ c = a + b #=> c=[1, 2, 3, 4, 5, 6] a=[1, 2, 3]
a << b #=> a=[1, 2, 3, [4, 5, 6]]
```

In addition `<<` modifies the first (the _receiver_) array whereas `+` returns a new array but leaves the receiver array unchanged. If, after appending an array with `<<` you decide that you’d like to add the elements from the appended array to the receiver array rather than have the appended array itself _nested_ inside the receiver, you can do this using the `flatten` method:
При додаванні через `<<` перший масив (_приймач_ або _receiver_) модифікується, тоді як `+` повертає новий масив, а масив–приймач залишає незмінненим. Якщо, після додавання в кінець масиву через `<<`, ви вирішете, що ви б хотіли додати елементи масиву, замість того, щоб _вкладати_ цілий масив масив–приймач, ви можете зробити це з допомогою методу `flatten`:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

через << ,(!) перший масив ..
Якщо(!) після додавання в кінець масиву через << (!) ви вирішИте, що хочете додати ..


**`hash1.rb`**:

You can create a hash by creating a new instance of the Hash class:
Ви можете створити хеш шляхом створення нового екземпляру класу `Hash`:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

екземпляра


Having created a Hash object, you can add items to it using an array-like syntax – that is, by placing the index in square brackets and using `=` to assign a value.
Моючи створений `Hash`–об’єкт ви можете додавати у нього елементи використовуючи синтаксис схожий на масиви: вказуючи індекс між квадратними дужками та використовуючи `=` для присвоєння значення.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у нього елементи,(!) використовуючи


The obvious difference here being that, with an array, the index (the ‘key’) must be an integer; with a Hash, it can be any unique data item:
Очевидна відмінність тут у тому, що для масивів індексом (_ключем_) має бути ціле число; для хешу це може бути будь-які унікальний елемент даних:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

будь-яким унікальним елементом

>
> Take care when assigning keys to Hashes. If you use the same key twice in a Hash, you will end up over-writing the original value. This is just like assigning a value twice to the same index in an array. Consider this example:
> Потурбуйтесь про присвоєння ключів в хеші. Якщо ви використовуєте один і той самий ключ двічі, ви перезаписуєте початкове значення. Це те саме, що і двічі присвоїти значення одному й тому ж індексові масиву. Розгляньте такий приклад:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

розглянемо


**`hash2.rb`**:

The `keys` and `values` methods of `Hash` each return an array so you can use various Array methods to manipulate them. Here are a few simple examples (note, the data shown in comments beginning `#=>` show the values returned when each piece of code is run):
Методи `keys` (ключі) та `values` (значення) для `Hash` повертають масиви, тож ви можете різні методи масивів, щоб маніпулювати ними. Ось кілька простих прикладів (зауважте, що значення, які отримаються в результаті запуску рядка коду показані у коментарях, що починаються з `#=>`):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

що значення, які отримаються в результаті запуску рядка коду,(!) показані

@denysdovhan denysdovhan added done and removed review labels Aug 29, 2017
@denysdovhan denysdovhan merged commit b006d95 into master Aug 29, 2017
@denysdovhan denysdovhan deleted the 06-hashes branch August 29, 2017 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants