feat: Add ruby code - chapter "array & linked list" (#1158)

* feat: add ruby code chapter array & linked list

- array.rb
- linked_list.rb
- list.rb
- my_list.rb

* feat: add ruby code blocks

* chore: fix convention
This commit is contained in:
khoaxuantu
2024-03-30 12:10:46 +07:00
committed by GitHub
parent e799513173
commit 85ca4cce43
12 changed files with 687 additions and 0 deletions
@@ -119,6 +119,14 @@ Arrays can be initialized in two ways depending on the needs: either without ini
var nums = [_]i32{ 1, 3, 2, 5, 4 };
```
=== "Ruby"
```ruby title="array.rb"
# Initialize array
arr = Array.new(5, 0) # [ 0, 0, 0, 0, 0 ]
nums = [1, 3, 2, 5, 4]
```
### Accessing Elements
Elements in an array are stored in contiguous memory spaces, making it simpler to compute each element's memory address. The formula shown in the Figure below aids in determining an element's memory address, utilizing the array's memory address (specifically, the first element's address) and the element's index. This computation streamlines direct access to the desired element.