jonsanders101
jonsanders101

Reputation: 525

How to tell in which version of Ruby a method was first introduced?

In the official Ruby documentation or elsewhere, is there an easy way of seeing in which version of Ruby a given method was first introduced to the language?

I haven't found such a resource and it seems it would be obviously useful.

Upvotes: 6

Views: 212

Answers (2)

noraj
noraj

Reputation: 4622

To complete @Grzegorz answer, you could look for the method you need at DevDocs or RubyAPI and then try to change version (eg. 3.0 -> 2.7, etc.) until the method is not documented.

The only direct method was with ApiDock but it's abandoned now and covers only from Ruby 1.8.6 to 2.6.3.

As of today the best (easiest and quickest) method is with DevDocs.

Add all Ruby versions available in DevDocs (2.2 to 3.0).

devdocs - ruby versions

The search your method and see the lowest match (eg. here with Regexp#match?) it's 2.4. If you want to be extra sure you can then check the corresponding ruby changelog.

devdocs - search

Upvotes: 1

Greg
Greg

Reputation: 6628

You could try checking out changelogs here https://github.com/ruby/ruby/blob/trunk/doc but it looks like they skipped few ;)

The only way I can think of is to have all major version binaries, and execute code on them to see if works. If you were looking for Hash#fetch you could run ruby -e 'Hash.new.fetch(0, 0)' each version which returns 0 will have it implemented, others means some error. You could use rvm for that.

You could automatize it with git bisect. But it would have to compile ruby binary for each check, and some dependencies could have changed so I would not expect it to work on first try :D

Upvotes: 1

Related Questions