Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The use of <code>File.join()</code> is wrong. <code>.join()</code> returns a string, and then applying <code>.last</code> to it generates an error, because there is no <code>.last</code> method for String objects.</p> <pre><code>pry(main)&gt; extension = '.xml' =&gt; ".xml" pry(main)&gt; File.join(extension).last NoMethodError: undefined method `last' for ".xml":String </code></pre> <p>Instead you need to pass an array of path elements you want to join into a path to a file:</p> <pre><code>pry(main)&gt; File.join('.', 'path', 'to', 'a', 'file.ext') =&gt; "./path/to/a/file.ext" </code></pre> <p>or:</p> <pre><code>pry(main)&gt; File.join('/', 'path', 'to', 'a', 'file.ext') =&gt; "/path/to/a/file.ext" </code></pre> <p>Take the time to read about Ruby's <a href="http://ruby-doc.org/core-1.9.3/File.html" rel="nofollow"><code>File</code></a> class. It allows you to work with the files and paths in a fairly OS-independent way.</p> <p>Its <code>dirname</code>, <code>basename</code>, and <code>extname</code> methods are convenient when dissecting paths:</p> <pre><code>pry(main)&gt; File.dirname('/path/to/a/file.ext') =&gt; "/path/to/a" pry(main)&gt; File.basename('/path/to/a/file.ext') =&gt; "file.ext" pry(main)&gt; File.extname('/path/to/a/file.ext') =&gt; ".ext" </code></pre> <p>There's also the <code>split</code> method which combines <code>dirname</code> and <code>basename</code>, returning both the path and "filename.ext" allowing you to use parallel assignment:</p> <pre><code>pry(main)&gt; dirname, filename = File.split('/path/to/a/file.ext') =&gt; ["/path/to/a", "file.ext"] </code></pre> <p><code>File.basename</code> takes an optional "extension" parameter, allowing it to strip off an extension:</p> <pre><code>pry(main)&gt; File.basename('/path/to/a/file.ext', '.ext') =&gt; "file" </code></pre> <p>Combine all that magical goodness and you can fold, spindle and mutilate your filenames and paths all day long.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload