Project

General

Profile

Actions

Bug #10294

closed

Dir[] cannot be called with an array argument

Added by Anonymous over 9 years ago. Updated over 9 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 2.2.0dev (2014-09-20 trunk 47651) [x86_64-darwin13]
[ruby-core:65265]

Description

The documentation for Dir[] claims that it can be called with an array and it will behave like Dir.glob:

Dir[ array ] → array
Dir[ string [, string ...] ] → array
Equivalent to calling Dir.glob(array,0) and Dir.glob([string,...],0).

However, doing so raises a TypeError:

$ ruby -e "puts Dir[['/bin/bash']]"
-e:1:in `[]': no implicit conversion of Array into String (TypeError)
	from -e:1:in `<main>'

Dir.glob works as documented:

$ ruby -e "puts Dir.glob ['/bin/bash']"
/bin/bash

I'm unsure if this is supposed to work as described or if it is a documentation bug, but it is reproducible on 2.0, 2.1, and trunk.

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Status changed from Open to Rejected

Not an array of path names, any number of path names,

Dir['/bin/bash', '/bin/sh']

Updated by Anonymous over 9 years ago

I'm aware of what actually works in practice, but the documentation claims both forms are acceptable:

Dir[ array ] → array
Dir[ string [, string ...] ] → array

https://github.com/ruby/ruby/blob/2a8989d71c611884631c4d9ff5dba65aed00cc83/dir.c#L1871-L1877

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Category set to doc
  • Status changed from Rejected to Open
  • Target version set to 2.2.0
  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r47850.


dir.c: fix rdoc [ci skip]

  • dir.c (dir_s_aref): fix rdoc. Dir.glob allows an array but
    Dir[] not. the former accepts an optional parameter flags,
    while the latter accepts arbitrary number of arguments but no
    flags. [ruby-core:65265] [Bug #10294]

Updated by usa (Usaku NAKAMURA) over 9 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED to 2.0.0: DONE, 2.1: REQUIRED

Backported into ruby_2_0_0 at r47934.

Updated by nagachika (Tomoyuki Chikanaga) over 9 years ago

  • Backport changed from 2.0.0: DONE, 2.1: REQUIRED to 2.0.0: DONE, 2.1: DONE

Backported into ruby_2_1 at r47946.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0