ruby 2.7.0 docs claim to have the String '/' method, but it doesn't seem to exist

Viewed 45

From:

https://ruby-doc.org/core-2.7.0/String.html#method-i-2F

It looks like we can do either of these to get a split:

got = str.split(',')
got = str/','

But the second one doesn't seem to work (and neither does './' or './(ch)' etc..), instead giving a method not found (MRI 2.7.0)

And in fact, I get nothing when I do:

 puts String.methods.index(:/)

(Although now that I've tried that on Integer, I see it doesn't show up there either)

Is this a bug in the docs?

1 Answers

This looks like an issue with the docs on ruby-doc.org.

The / alias for String#split has never (as far as I can see) been part of regular String, but it is part of golf_prelude.rb.

golf_prelude.rb is part of a special version of Ruby intended for code golf. You can’t just require 'golf_prelude' to use it though, you need to make a special build which includes it.

The documentation for String#/ appears in ruby-doc.org through to Ruby 3.1.0, but it does’t appear in 3.1.1 onwards. Other methods from golf_prelude.rb are also documented for versions up to 3.1.0, e.g. Object#h, Symbol#call and Integer#each, even though they don’t actually exist in normal Ruby and have been removed from the 3.1.1 documentation.

If you look at the “In Files” part of the documentation for these classes (at the top left of the page) you will see that the 3.1.0 versions all list golf_prelude.rb while the 3.1.1 versions don’t.

There doesn’t appear to be any changes in the Ruby source between these two versions to explain the difference in the docs (at least not that I can find). My assumption is that the maintainers of ruby-doc.org noticed they were erroneously including this file when generating the site and altered their build script to exclude it.

(Although now that I've tried that on Integer, I see it doesn't show up there either)

Neither String or Integer, being classes, have a / method (even in the golf version), but instances of Integer (but not String – unless golfing) do:

String.instance_methods.index(:/)
=> nil
Integer.instance_methods.index(:/)
=> 32
Related