How do I install the Ruby ri documentation?

前端 未结 8 1284
既然无缘
既然无缘 2020-12-05 02:56

I\'ve recently installed Ruby 1.9.1 on Windows 7, and apparently it doesn\'t come with the standard ri documentation. So when I do \'ri Array\', I get:

C:\\         


        
相关标签:
8条回答
  • 2020-12-05 03:13

    RVM does not automatically generate and install each Ruby's ri / rdoc documentation. You can generate using the following command: rvm docs generate

    0 讨论(0)
  • 2020-12-05 03:17

    You might run into this issue under Docker. The official docker images come with no documentation, and apparently disable installing gem documentation.

    If image's and system ruby versions match (specifically, RbConfig::CONFIG["ruby_version"], which is e.g. 2.6.0 for ruby-2.6.1), you can:

    # apk add ruby-doc
    # cp -r /usr/share/ri /usr/local/share/ri
    
    0 讨论(0)
  • 2020-12-05 03:18

    If you are using rvm you should rvm docs generate (or just rvm docs generate-ri)

    See this info (2011August) about rvm and ri

    0 讨论(0)
  • 2020-12-05 03:24

    Things are still largely the same with Ruby Installer 2.4.1.2 (year 2017). If I run ri Array, it shows Array < Object and nothing else. If I run ri "Array#each", I get the familiar "Nothing known..." message. In short, the ri-format documentation on Ruby core and standard libraries are missing.

    Here's how I got my copy of core/stdlib ri-documentation. Of course, Ruby must be installed prior to this.

    1. Get ruby's source code that most closely matches my version from their Github releases page.
    2. Extract the .zip or .tar.gz archive to some folder
    3. Open cmd.exe/Powershell, cd to that folder and run rdoc --all --ri
      • This command parses .c files, .rb files, and a few other file types in the current directory recursively and generates ri-documentation to ~/.rdoc directory.
      • Took about 5 minutes on my laptop with i7-3520M processor to complete, with no errors.
    4. Delete the archive and the directory containing the source code because we don't need them anymore.

    Now if you try running ri Array or ri "Array#each" you'll get the documentation in all its glory.

    tl;dr

    Run rdoc --all --ri on directory containing source code for same ruby version as your installed version.


    Appendix Z: Comments on other answers

    1. The rvm docs generate-ri could work, but you have to use Cygwin or Ubuntu on Windows (if on Windows 10) to use rvm.
    2. gem rdoc --all --ri --no-rdoc installs ri-documentation for all your gems. It doesn't install the core/stdlib documentations.
    3. gem install rdoc-data followed by rdoc-data --install only works for Ruby versions up to 2.3.0.
    0 讨论(0)
  • 2020-12-05 03:28

    In case people on other platforms need to install their ri docs (like I did). This article gives the why and the how:

    http://jstorimer.com/ri.html

    The command is:

    gem rdoc --all --ri --no-rdoc
    
    0 讨论(0)
  • 2020-12-05 03:28

    All the Ruby Docs are at http://www.ruby-doc.org

    So the array documentation is at:

    http://ruby-doc.org/core/classes/Array.html

    Never tried it on windows but because its saying Nothing Known about X its not that its not installed just not got anything there.

    Try installing a gem as you can then ri GEM_CLASS as that should provide defentions, should let us see if its missing documentation or if ri's not looking in the right place

    0 讨论(0)
提交回复
热议问题