Overview
File class of ruby provides the below method that can be used to check if a file is writable by the effective user and group id of the current process.
Here is the signature of the function
writable?(file_name)
It returns true if the file is writable or else it will return false.
Program
Create a file named test.txt in the current directory. With the same user run the below program
writable = File.writable?("test.txt")
puts writable
Output
true
Now change the user and group id of the test.txt file using chown command. Make sure that the current user doesn’t belong to the new group id.
Run the above program again. This time it will output false.