Block size refers to the amount of disk space allocated to a file. It can also represent the largest amount of data that can be transferred in a single output and operation on a file. To get this value, we can use the
blksize property of the
stat, which stands for the status of a file.
filename: This is the name of the file that we want to get block size information for.
This method returns an integer representing the block size of a file.
Let's look at the code below:
# get current file and print block size puts "The block size of this file is:" puts File.stat("main.rb").blksize
blksizeto get the block size of our application file
main.rb, and we print it to the console.
View all Courses