Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Pathname#chardev?

() -> bool
chardev? => true or false

Returns whether self represents a path to a character device (i.e., a sequential-access device):

Example
Pathname('/dev/tty').chardev?     # => true
Pathname('/dev/null').chardev?    # => true
Pathname('/dev/nvme0n1').chardev? # => false
Pathname('/dev/loop0').chardev?   # => false
Pathname($stdin).chardev?         # => false
Pathname('nosuch').chardev?       # => false

The returned value is filesystem-dependent; on Windows, always false.

See also #blockdev? #children #birthtime #chmod also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0