Pathname.new(Dir.new('dir_name')) raises a TypeError #1154

Closed
senorprogrammer opened this Issue Oct 23, 2013 · 2 comments

Projects

None yet

2 participants

@senorprogrammer

Pathname.new should be able to accept a bare Dir.new instance as a param.

Expected Result

Returns a new instance of Pathname build from the Dir instance.

Actual Result

Raises a TypeError.

Steps to Reproduce

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)
@enebo
Member
enebo commented Oct 23, 2013

Ah simple missing method. Dir.to_path does not exist. I will add that.

@enebo enebo closed this in 02a9d82 Oct 23, 2013
@senorprogrammer

Thanks Thomas!

@enebo enebo added a commit that referenced this issue Oct 24, 2013
@enebo enebo Fixes #1154. Pathname.new(Dir.new('dir_name')) raises a TypeError (Di…
…r missing to_path)
4a3b088
@enebo enebo added a commit that referenced this issue Oct 24, 2013
@enebo enebo Fixes #1154. Pathname.new(Dir.new('dir_name')) raises a TypeError (Di…
…r missing to_path)
babf3c9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment