Skip to content

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

class method

File.chardev?

(::path | ::IO file_name) -> bool
File.chardev?(object) → true or false

Returns whether object (a path or IO object) represents a character device (i.e., a sequential-access device):

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

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

See also .blockdev? .chmod .birthtime .chown also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0