Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.