How can I get the filename without the extensions? For example, input of "/dir1/dir2/test.html.erb"
should return "test"
.
In actual code I will passing in __FILE__
instead of "/dir1/dir2/test.html.erb"
.
Read documentation:
basename(file_name [, suffix] ) → base_name
Returns the last component of the filename given in file_name, which can be formed using both File::SEPARATOR and File::ALT_SEPARATOR as the separator when File::ALT_SEPARATOR is not nil. If suffix is given and present at the end of file_name, it is removed.
=> File.basename('public/500.html', '.html') => "500"
in you case:
=> File.basename("test.html.erb", ".html.erb") => "test"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With