Skip to content

Instantly share code, notes, and snippets.

@senorprogrammer
Last active December 26, 2015 08:39
Show Gist options
  • Save senorprogrammer/7123977 to your computer and use it in GitHub Desktop.
Save senorprogrammer/7123977 to your computer and use it in GitHub Desktop.
Whether or not Pathname + Dir on jRuby behaves differently than in MRI

Test code (run from the Documents directory of a standard OS X user account).

d = Dir.new('Pictures')

pn = Pathname.new(d)

dir = pn.children.find { |child| child.directory? && child.basename.to_s == 'GoPro' }
puts dir.inspect

JRuby 1.7.5 result:

‼ ⚡ ruby dir_test.rb
TypeError: can't convert Dir into String
initialize at org/jruby/ext/pathname/RubyPathname.java:201
      (root) at dir_test.rb:7

MRI 1.9.3-p392 result:

✔ ⚡ ruby dir_test.rb
#<Pathname:Pictures/GoPro>

Work-around:

pn = Pathname.new(d.path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment