Skip to content

Commit

Permalink
Update ruby and pacman notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yutsuten committed Jan 31, 2025
1 parent 6f7988c commit def7b2e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
11 changes: 11 additions & 0 deletions notes/language/ruby/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ref: https://docs.ruby-lang.org/en/3.4/Array.html
my_array = Array.new
my_array = [1, 2, 3]
my_array = (1..10).to_a
my_words = %w[foo bar] # %W if going to use string interpolation

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

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

Iterate array elements:

```ruby
array.each do |element|
puts element
end
```

Update elements order:

```ruby
Expand Down
16 changes: 8 additions & 8 deletions notes/language/ruby/builtin.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
title: Built-in
---

## Interactive Console
## Usage

Run the command:
Usually it is expected to have the default tools and libraries.

```shell
pacman -S ruby-stdlib
```

Open the interactive console:

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

[String formatting](https://docs.ruby-lang.org/en/3.4/format_specifications_rdoc.html):

```ruby
sprintf('%.1f', 8.199)
```

Getting user input:

```ruby
Expand Down
6 changes: 3 additions & 3 deletions notes/language/ruby/hash.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ Create filled hash:
```ruby
my_hash = {
'name' => 'Taro',
'age' => 24,
'age' => 24
}
my_hash = {
:name => 'Taro',
:age => 24,
:age => 24
}
my_hash = {
name: 'Taro', # Becomes symbol
age: 24, # Becomes symbol
age: 24 # Becomes symbol
}
```

Expand Down
16 changes: 16 additions & 0 deletions notes/language/ruby/string.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,28 @@ ref: https://docs.ruby-lang.org/en/3.4/String.html

## Basic

To make strings immutable (recommended),
add this the first line of the script:

```ruby
# frozen_string_literal: true
```

Instantiation:

```ruby
my_string = 'Taro'
interpolation = "Hello, #{name}"
my_string << 'concatenate me'
```

[String formatting](https://docs.ruby-lang.org/en/3.4/format_specifications_rdoc.html):

```ruby
format('%.1f', 8.199) # Preferred
sprintf('%.1f', 8.199)
```

### Methods

| Method | Description |
Expand Down
7 changes: 7 additions & 0 deletions notes/tool/linux/arch/pacman.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ ref: https://wiki.archlinux.org/title/Pacman
| `pacman -Qett` | List all packages explicitly installed and not required as dependencies (required only) |
| `pacman -Qi package` | Check information of a package that is installed. |
| `pacman -Si package` | Check information of a package that may not be installed. |
| `pacman -D --asdeps` | Mark the specified package as installed as a dependency. |

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

```fish
diff -y (pacman -Qqett | psub) (pacman -Qqe | psub)
```

Mark a package as installed as a dependency.

```fish
sudo pacman -D --asdeps ruby
```

## Configuration

### Parallel downloads
Expand Down

0 comments on commit def7b2e

Please sign in to comment.