Skip to content

Commit def7b2e

Browse files
committed
Update ruby and pacman notes
1 parent 6f7988c commit def7b2e

File tree

5 files changed

+45
-11
lines changed

5 files changed

+45
-11
lines changed

notes/language/ruby/array.md

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ref: https://docs.ruby-lang.org/en/3.4/Array.html
99
my_array = Array.new
1010
my_array = [1, 2, 3]
1111
my_array = (1..10).to_a
12+
my_words = %w[foo bar] # %W if going to use string interpolation
1213

1314
my_array[1]
1415
my_array.push(40)
@@ -23,9 +24,11 @@ my_array << 40 # Same as push
2324
| `max` | Returns the biggest element in the array. |
2425
| `min` | Returns the smallest element in the array |
2526
| `include?` | Returns `true` if the array includes the specified element. |
27+
| `empty?` | Returns `true` if the length of the array is 0. |
2628
| `sort` | Returns a new array sorted. |
2729
| `sort_by!` | Sort in place by using the given block. |
2830
| `reverse` | Returns a new array in inverse order. |
31+
| `each` | Iterate over the elements of the array. |
2932
| `map` | Returns a new array with each element updated by the given block. |
3033
| `collect` | Same as `map`. |
3134

@@ -35,6 +38,14 @@ Check if array includes an element:
3538
my_array.include? 'critical'
3639
```
3740

41+
Iterate array elements:
42+
43+
```ruby
44+
array.each do |element|
45+
puts element
46+
end
47+
```
48+
3849
Update elements order:
3950

4051
```ruby

notes/language/ruby/builtin.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
title: Built-in
33
---
44

5-
## Interactive Console
5+
## Usage
66

7-
Run the command:
7+
Usually it is expected to have the default tools and libraries.
8+
9+
```shell
10+
pacman -S ruby-stdlib
11+
```
12+
13+
Open the interactive console:
814

915
```shell
1016
irb
@@ -19,12 +25,6 @@ print 'Hello' # Prints something and do NOT put a new line
1925
puts 'Hello' # Prints something and puts a new line at the end
2026
```
2127

22-
[String formatting](https://docs.ruby-lang.org/en/3.4/format_specifications_rdoc.html):
23-
24-
```ruby
25-
sprintf('%.1f', 8.199)
26-
```
27-
2828
Getting user input:
2929

3030
```ruby

notes/language/ruby/hash.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ Create filled hash:
1717
```ruby
1818
my_hash = {
1919
'name' => 'Taro',
20-
'age' => 24,
20+
'age' => 24
2121
}
2222
my_hash = {
2323
:name => 'Taro',
24-
:age => 24,
24+
:age => 24
2525
}
2626
my_hash = {
2727
name: 'Taro', # Becomes symbol
28-
age: 24, # Becomes symbol
28+
age: 24 # Becomes symbol
2929
}
3030
```
3131

notes/language/ruby/string.md

+16
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,28 @@ ref: https://docs.ruby-lang.org/en/3.4/String.html
55

66
## Basic
77

8+
To make strings immutable (recommended),
9+
add this the first line of the script:
10+
11+
```ruby
12+
# frozen_string_literal: true
13+
```
14+
15+
Instantiation:
16+
817
```ruby
918
my_string = 'Taro'
1019
interpolation = "Hello, #{name}"
1120
my_string << 'concatenate me'
1221
```
1322

23+
[String formatting](https://docs.ruby-lang.org/en/3.4/format_specifications_rdoc.html):
24+
25+
```ruby
26+
format('%.1f', 8.199) # Preferred
27+
sprintf('%.1f', 8.199)
28+
```
29+
1430
### Methods
1531

1632
| Method | Description |

notes/tool/linux/arch/pacman.md

+7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@ ref: https://wiki.archlinux.org/title/Pacman
1717
| `pacman -Qett` | List all packages explicitly installed and not required as dependencies (required only) |
1818
| `pacman -Qi package` | Check information of a package that is installed. |
1919
| `pacman -Si package` | Check information of a package that may not be installed. |
20+
| `pacman -D --asdeps` | Mark the specified package as installed as a dependency. |
2021

2122
Check packages explicitly installed but required dependency at the same time.
2223

2324
```fish
2425
diff -y (pacman -Qqett | psub) (pacman -Qqe | psub)
2526
```
2627

28+
Mark a package as installed as a dependency.
29+
30+
```fish
31+
sudo pacman -D --asdeps ruby
32+
```
33+
2734
## Configuration
2835

2936
### Parallel downloads

0 commit comments

Comments
 (0)