To find the extension of a JSON file in Ruby, you can use the File.extname
method. Here's an example code snippet:
main.rb152 chars6 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