Giter VIP home page Giter VIP logo

sixarm_ruby_pathname_dirnames's Introduction

SixArm.com → Ruby →
Pathname#dirnames method to iterate on parent directories

Introduction

This gem has one method: Pathname#dirnames.

It will return an enumerable of pathnames created by calling #dirname repeatedly.

This can be useful for traversing directories upwards to parent, grandparent, etc.

Example:

 p = Pathname.new('/foo/goo/hoo.txt')
 p.dirnames
 #=> ['/foo/goo', '/foo', '/']

For docs go to http://sixarm.com/sixarm_ruby_pathname_dirnames/doc

Want to help? We're happy to get pull requests.

Install

Gem

To install this gem in your shell or terminal:

gem install sixarm_ruby_pathname_dirnames

Gemfile

To add this gem to your Gemfile:

gem 'sixarm_ruby_pathname_dirnames'

Require

To require the gem in your code:

require 'sixarm_ruby_pathname_dirnames'

Example to find a file

To find the first occurance of a file named "my.txt" in a path or its parents:

 basename = "my.txt"
 p = Pathname.new('/foo/goo/hoo/*')
 puts p.dirnames.find{|dirname| (dirname + basename).exist?}

Note that the "" at the end of the pathname is to give dirname something to chop off; the "" is being used as chaff, not as a file matcher nor string matches.

sixarm_ruby_pathname_dirnames's People

Contributors

joelparkerhenderson avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.