Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add file.basename #64

Merged
merged 1 commit into from
Feb 5, 2016
Merged

feature: add file.basename #64

merged 1 commit into from
Feb 5, 2016

Conversation

arlimus
Copy link
Contributor

@arlimus arlimus commented Feb 5, 2016

No description provided.

@arlimus arlimus force-pushed the dr/basename branch 3 times, most recently from 0998ffe to 3cba6bf Compare February 5, 2016 11:47
@srenatus
Copy link
Contributor

srenatus commented Feb 5, 2016

Hmm... we could have employed Pathname, couldn't we?

It does not represent the file itself. A Pathname can be relative or absolute. It’s not until you try to reference the file that it even matters whether the file exists or not.

@arlimus
Copy link
Contributor Author

arlimus commented Feb 5, 2016

@srenatus basename for Pathname defaults to the running system's separator. When we are targeting a remote system, that might be local=Unix vs remote=Windows. Afaics, pathname doesn't provide us with a configurable separator. The docs point from Pathname.basename to File.basename:

See File.basename. Returns the last component of the path.

which in turn:

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. If suffix is “.*”, any extension will be removed.

Try:

Pathname.new('C:\hello\world').basename

@arlimus
Copy link
Contributor Author

arlimus commented Feb 5, 2016

Unless you know how to do that?

@srenatus
Copy link
Contributor

srenatus commented Feb 5, 2016

Nah, you're right. I mistook the "suffix" thing for the ability to pass a separator :/

Can't even get Pathname to work when I override File::SEPARATOR...

@arlimus
Copy link
Contributor Author

arlimus commented Feb 5, 2016

Oh wow, I was expecting it to work at least that far... well, really hate to duplicate code, but ... 🐹

@chris-rock
Copy link
Contributor

Thanks for this feature @arlimus

chris-rock added a commit that referenced this pull request Feb 5, 2016
feature: add file.basename
@chris-rock chris-rock merged commit ee0e98c into master Feb 5, 2016
@chris-rock chris-rock deleted the dr/basename branch February 5, 2016 13:08
@chris-rock chris-rock added this to the 0.9.7 milestone Feb 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants