Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ruby
communitycreator

What is File.ftype() in Ruby?

okwudili onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

We use the ftype() function of a File class in Ruby to identify the type of a file. It returns the string file, directory, characterSpecial, blockSpecial, fifo, link, socket, or unknown.

Syntax

File.ftype(file_name)

Parameter

file_name: This is the file name whose file type we want to get.

Return value

The string returns the string file, directory, characterSpecial, blockSpecial, fifo, link, socket, or unknown.

Code example

main.rb
hmm.tty
hmm.X0
app.js
Get the file type of some files in Ruby

Explanation

We create some files and our application code main.rb.

  • Line 2-5: We get the file names.
  • Line 8-11: We print the name types of the file to the console.

RELATED TAGS

ruby
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring