Project

General

Profile

Actions

Feature #16688

open

Allow #to_path object as argument to system()

Added by Dan0042 (Daniel DeLorme) over 4 years ago. Updated over 4 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:97448]

Description

I often work with Pathname objects, but when passing them to a system command I find it a bit tedious that they have to be explicitly converted to a String.

file = BASE + "config.json"
system(@cmd, file)      #=> TypeError (no implicit conversion of Pathname into String)
system(@cmd, file.to_s) #=> works

I propose that the system/exec/spawn family of methods should try to convert their arguments using to_path, if to_str fails. I believe it makes perfect sense, since commandline arguments are so often pathnames.

This includes in/out redirection. system("ls", out: Pathname.new("file")) should be valid.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0