alf-tool / alf-core

Core classes, the kernel of Alf
MIT License
50 stars 5 forks source link

accept any kind of path for Alf::Reader.reader #1

Closed eregon closed 12 years ago

eregon commented 12 years ago

The documentation should be updated, but I don't speak (yet) YARD, so please teach me.

Pathname use :to_str in 1.8, :to_path in 1.9. Path now defines both. So checking only :to_str would be enough if you do not plan to accept Pathname.

This is an easy way (because it converts directly to String) to solve the current situation with Viiite. Alf should ideally support paths everywhere, but Ruby is not really helpful here (there should be a class for paths, which would avoid the confusion between String (potentially IO contents) and paths), and you would need to check like I do here everywhere you use a path.

If used in a case statement, you could probably define something like

KindOfPath = lambda do |path|
  path.respond_to? :to_str or path.respond_to? :to_path
end

case path
-when String
+when KindOfPath
end

-if path.is_a? String
+if KindOfPath === path