eregon/alf — comment on commit 60aee08d0074cc25fb90934b40c1936249a95541
File:  line 0
By eregon:

Yes, File.extname use the FilePathStringValue() macro, which is replaced by rb_get_path_no_checksafe(), which tries to convert the object to a path by:

* checking if a String (type = T_STRING)
* tries to convert to a path with :to_path (only on 1.9)
* tries to convert to a String using :to_str

Except if you like some C to wake up (which I do), the easiest (and safest) way is to check RubySpec, here https://github.com/rubyspec/rubyspec/blob/master/core/file/extname_spec.rb

Pathname defines :to_str in 1.8, :to_path in 1.9, but not both. So calling either one is unsafe, only :to_s is common (plus, :to_str and other full qualified conversion like :to_int should not need to be called for conversion, the object is already expected to answer to (here) String-like methods (which is why :to_str was a bad convention, as Pathname does not respond to :tr for example)).

```ruby
class Pathname
if RUBY_VERSION < "1.9"
TO_PATH = :to_str
else
# to_path is implemented so Pathname objects are usable with File.open, etc.
TO_PATH = :to_path
end
end
```