find the extension of a json file in ruby

To find the extension of a JSON file in Ruby, you can use the File.extname method. Here's an example code snippet:

main.rb
file_name = "example.json"
extension = File.extname(file_name) # ".json"

# If you want to remove the dot
extension_without_dot = extension.delete(".")
152 chars
6 lines

In this example, the file_name variable contains the name of the file, and we use File.extname to find the extension of the file. The method returns the extension with a dot (".json" in this case), so we remove the dot using the delete method if necessary.

gistlibby LogSnag