Project

General

Profile

Actions

Feature #7360

closed

Adding Pathname#glob

Added by aef (Alexander E. Fischer) about 12 years ago. Updated about 7 years ago.

Status:
Closed
Target version:
-
[ruby-core:49373]

Description

Currently there is only a Pathname.glob method, which allows you to find Pathname objects by a pattern including wildcard characters like '*'.

I would like to be able to use this relative to a current Pathname.

some_directory = Pathname.new('some_directory')
Pathname.glob(some_directory + 'a*') # all children starting with "a"

could then simply be:

some_directory.glob('a*') # all children starting with "a"

If you like the idea, please let me know. I will provide a patch then.


Files


Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #7378: Adding Pathname#writeClosedakr (Akira Tanaka)06/02/2012Actions
Blocked by Ruby master - Feature #13056: base option to Dir.globClosedActions

Updated by mame (Yusuke Endoh) about 12 years ago

  • Status changed from Open to Assigned
  • Assignee set to akr (Akira Tanaka)
  • Target version set to 2.6
Actions #2

Updated by til (Tilmann Singer) about 9 years ago

Here is a patch that adds the functionality as outlined by Alexander. It's using "Pathname#join" to build the glob pattern, and then delegating to "Pathname.glob".

As described in the rdoc, it will accept a single string with a glob pattern, or an array of glob patterns.

The main use case is when you want to do something based relative to a current directory that is already available as Pathname, such as Rails.root in a Rails project. With this, you can say e.g.

Rails.root.glob("*.rb")

to find all ruby files in the current project.

Link to the branch of my fork on GitHub:

https://github.com/til/ruby/tree/add-pathname-glob-instance-method

Updated by til (Tilmann Singer) about 8 years ago

The patch still applies to latest trunk.

Updated by akr (Akira Tanaka) about 8 years ago

  • Status changed from Assigned to Feedback

It seems the proposed implementation treats the receiver as a glob pattern.

% ruby -rpathname -e '
class Pathname
  def glob(pattern, flags = 0, &b)
    Array(pattern).flat_map do |pat|
      self.class.glob(join(pat), flags, &b)
    end
  end
end
p Pathname("/b*").glob("i*") 
'
[#<Pathname:/boot/initrd.img-3.16.0-4-amd64>, #<Pathname:/bin/ip>]

I think it is not intentional.

Actions #6

Updated by nobu (Nobuyoshi Nakada) about 8 years ago

Updated by shyouhei (Shyouhei Urabe) about 8 years ago

We looked at this issue at today's developer meeting. As Akira already respond, the proposed patch has a problem. In order to reroute that we need to extend Dir.glob. Nobu opened a ticker for that. Once he finished that, we can resume this one.

Actions #8

Updated by akr (Akira Tanaka) about 7 years ago

  • Status changed from Feedback to Closed

Applied in changeset trunk|r60238.


Pathname#glob method implemented.

[ruby-core:49373] [Feature #7360] proposed by Alexander E. Fischer.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0