method
extname
![Moderate documentation Importance_2](https://d2vfyqvduarcvs.cloudfront.net/images/importance_2.png?1349367920)
extname(p1)
public
Returns the extension (the portion of file name in path starting from the last period).
If path is a dotfile, or starts with a period, then the starting dot is not dealt with the start of the extension.
An empty string will also be returned when the period is the last character in path.
File.extname("test.rb") #=> ".rb" File.extname("a/b/d/test.rb") #=> ".rb" File.extname("foo.") #=> "" File.extname("test") #=> "" File.extname(".profile") #=> "" File.extname(".profile.sh") #=> ".sh"
Register or
log in
to add new notes.
metavida -
January 27, 2010
![Default_avatar_30](https://www.gravatar.com/avatar/b526ab2828ebed7151e14174a8d242d4?default=http://apidock.com/images/default_avatar_30.png&size=30)
1 thank
File name without the extension
To get the file name without the extension you can use File.extname in combination with File.basename
File.basename("test.rb", File.extname("test.rb")) #=> "test" File.basename("a/b/d/test.rb", File.extname("a/b/d/test.rb")) #=> "test" File.basename("test", File.extname("test")) #=> "test" File.basename(".profile", File.extname(".profile")) #=> ".profile"