Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0cc61938df88
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b9c11957aa2b
Choose a head ref
  • 4 commits
  • 4 files changed
  • 3 contributors

Commits on Jan 5, 2018

  1. Copy the full SHA
    dd19fb3 View commit details
  2. Implement Dir.children

    For more information, please see feature #11302.
    nomadium committed Jan 5, 2018
    Copy the full SHA
    f5a7ef6 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5233dfd View commit details
  4. Merge pull request #4941 from nomadium/implement-dir-children

    Implement Dir.children
    enebo authored Jan 5, 2018
    Copy the full SHA
    b9c1195 View commit details
Showing with 24 additions and 6 deletions.
  1. +2 −2 core/pom.rb
  2. +2 −2 core/pom.xml
  3. +11 −0 core/src/main/java/org/jruby/RubyDir.java
  4. +9 −2 test/mri/ruby/test_dir.rb
4 changes: 2 additions & 2 deletions core/pom.rb
Original file line number Diff line number Diff line change
@@ -167,8 +167,8 @@
'compilerArgs' => { 'arg' => '-J-Xmx1G' },
'showWarnings' => 'true',
'showDeprecation' => 'true',
'source' => [ '${base.java.version}', '1.7' ],
'target' => [ '${base.javac.version}', '1.7' ],
'source' => [ '${base.java.version}', '1.8' ],
'target' => [ '${base.javac.version}', '1.8' ],
'useIncrementalCompilation' => 'false' ) do
execute_goals( 'compile',
:id => 'anno',
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -536,9 +536,9 @@ DO NOT MODIFIY - GENERATED CODE
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<source>${base.java.version}</source>
<source>1.7</source>
<source>1.8</source>
<target>${base.javac.version}</target>
<target>1.7</target>
<target>1.8</target>
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
11 changes: 11 additions & 0 deletions core/src/main/java/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
@@ -354,6 +354,17 @@ public static IRubyObject chroot(IRubyObject recv, IRubyObject path) {
throw recv.getRuntime().newNotImplementedError("chroot not implemented: chroot is non-portable and is not supported.");
}

/**
* Returns an array containing all of the filenames except for "." and ".."
* in the given directory.
*/
@JRubyMethod(name = "children", meta = true)
public static RubyArray children(ThreadContext context, IRubyObject recv, IRubyObject arg) {
RubyArray entries = entries19(context, recv, arg);
entries.removeIf(f -> f.equals(".") || f.equals(".."));
return entries;
}

/**
* Deletes the directory specified by <code>path</code>. The directory must
* be empty.
11 changes: 9 additions & 2 deletions test/mri/ruby/test_dir.rb
Original file line number Diff line number Diff line change
@@ -184,19 +184,26 @@ def test_glob_recursive
end
end

def assert_entries(entries)
def assert_entries(entries, children_only = false)
entries.sort!
assert_equal(%w(. ..) + ("a".."z").to_a, entries)
expected = ("a".."z").to_a
expected = %w(. ..) + expected unless children_only
assert_equal(expected, entries)
end

def test_entries
assert_entries(Dir.open(@root) {|dir| dir.entries})
assert_entries(Dir.entries(@root).to_a)
end

def test_foreach
assert_entries(Dir.foreach(@root).to_a)
end

def test_children
assert_entries(Dir.children(@root), true)
end

def test_dir_enc
dir = Dir.open(@root, encoding: "UTF-8")
begin