File tree 5 files changed +45
-11
lines changed
5 files changed +45
-11
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ ref: https://docs.ruby-lang.org/en/3.4/Array.html
9
9
my_array = Array .new
10
10
my_array = [1 , 2 , 3 ]
11
11
my_array = (1 ..10 ).to_a
12
+ my_words = %w[foo bar] # %W if going to use string interpolation
12
13
13
14
my_array[1 ]
14
15
my_array.push(40 )
@@ -23,9 +24,11 @@ my_array << 40 # Same as push
23
24
| ` max ` | Returns the biggest element in the array. |
24
25
| ` min ` | Returns the smallest element in the array |
25
26
| ` include? ` | Returns ` true ` if the array includes the specified element. |
27
+ | ` empty? ` | Returns ` true ` if the length of the array is 0. |
26
28
| ` sort ` | Returns a new array sorted. |
27
29
| ` sort_by! ` | Sort in place by using the given block. |
28
30
| ` reverse ` | Returns a new array in inverse order. |
31
+ | ` each ` | Iterate over the elements of the array. |
29
32
| ` map ` | Returns a new array with each element updated by the given block. |
30
33
| ` collect ` | Same as ` map ` . |
31
34
@@ -35,6 +38,14 @@ Check if array includes an element:
35
38
my_array.include? ' critical'
36
39
```
37
40
41
+ Iterate array elements:
42
+
43
+ ``` ruby
44
+ array.each do |element |
45
+ puts element
46
+ end
47
+ ```
48
+
38
49
Update elements order:
39
50
40
51
``` ruby
Original file line number Diff line number Diff line change 2
2
title : Built-in
3
3
---
4
4
5
- ## Interactive Console
5
+ ## Usage
6
6
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:
8
14
9
15
``` shell
10
16
irb
@@ -19,12 +25,6 @@ print 'Hello' # Prints something and do NOT put a new line
19
25
puts ' Hello' # Prints something and puts a new line at the end
20
26
```
21
27
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
-
28
28
Getting user input:
29
29
30
30
``` ruby
Original file line number Diff line number Diff line change @@ -17,15 +17,15 @@ Create filled hash:
17
17
``` ruby
18
18
my_hash = {
19
19
' name' => ' Taro' ,
20
- ' age' => 24 ,
20
+ ' age' => 24
21
21
}
22
22
my_hash = {
23
23
:name => ' Taro' ,
24
- :age => 24 ,
24
+ :age => 24
25
25
}
26
26
my_hash = {
27
27
name: ' Taro' , # Becomes symbol
28
- age: 24 , # Becomes symbol
28
+ age: 24 # Becomes symbol
29
29
}
30
30
```
31
31
Original file line number Diff line number Diff line change @@ -5,12 +5,28 @@ ref: https://docs.ruby-lang.org/en/3.4/String.html
5
5
6
6
## Basic
7
7
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
+
8
17
``` ruby
9
18
my_string = ' Taro'
10
19
interpolation = " Hello, #{ name } "
11
20
my_string << ' concatenate me'
12
21
```
13
22
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
+
14
30
### Methods
15
31
16
32
| Method | Description |
Original file line number Diff line number Diff line change @@ -17,13 +17,20 @@ ref: https://wiki.archlinux.org/title/Pacman
17
17
| ` pacman -Qett ` | List all packages explicitly installed and not required as dependencies (required only) |
18
18
| ` pacman -Qi package ` | Check information of a package that is installed. |
19
19
| ` 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. |
20
21
21
22
Check packages explicitly installed but required dependency at the same time.
22
23
23
24
``` fish
24
25
diff -y (pacman -Qqett | psub) (pacman -Qqe | psub)
25
26
```
26
27
28
+ Mark a package as installed as a dependency.
29
+
30
+ ``` fish
31
+ sudo pacman -D --asdeps ruby
32
+ ```
33
+
27
34
## Configuration
28
35
29
36
### Parallel downloads
You can’t perform that action at this time.
0 commit comments