Does ri know about all ruby classes? - ruby

When I pass CSV to ri I get this output
Nothing known about CSV
I thought all ruby classes are documented with ri.

CSV is a part of standard library and is fully documented. That issue may be linked wit rvm using. Try to prepare rvm docs generate command.

If RI returns "NOTHING KNOWN ABOUT..." the documentation may be missing.
RI documentation isn't included when Ruby is installed.
It must be manually generated - ideally, immediately after installing EACH VERSION of Ruby (before the downloaded installation files are cleaned up).
To generate it:
$ rvm docs generate
If that doesn't work, check this RVM.io page for command options & scenarios.

Related

How do I get rrdtool from homebrew to work with ruby on macOS

In our Rails application we do require 'RRD' at some point, but that results in a cannot load such file -- RRD. So obviously I used homebrew to install rrdtool, but the error remains.
The docs at https://oss.oetiker.ch/rrdtool/prog/rrdruby.en.html provide two options:
Either:
$: << '/path/to/rrdtool/lib/ruby/1.8/i386-linux'
require "RRD"
In my /opt/homebrew/Cellar/rrdtool/1.8.0/lib directory there's no mention of ruby, which is because of the --disable-ruby-site-install flag in the formula, because when I skip that flag I do actually get something: /opt/homebrew/Cellar/rrdtool/1.8.0/lib/ruby/2.6.0/universal-darwin21. However replacing the path/to string with this path still gives the error.
Or:
If you use the --ruby-site-install configure option you can drop the $: line since the RRDtool module will be found automatically.
Which is a little confusing (and probably outdated) because here it seems that ruby site install is disabled by default and you have to enable it proactively, whereas in the formula it's actually actively disabled.
Either way: both options didn't do the trick for me and if there's a solution without homebrew that's also fine.
For good measure: I'm on macOS Monterey
TL;DR
For the most part, I'd say that using a non-standard gem without a Ruby version manager is your main issue. There are instructions on the rrdruby site for installing it, but they don't follow typical conventions, so your mileage will vary.
Some Practical Suggestions
The require keyword is for gems, not binaries. You need to have an rrdtool-related gem installed, available to your Ruby instance (usually through a Bundler Gemfile or gemspec, or via the RUBYOPTS environment variable or your in-process Ruby $LOAD_PATH), and then require the correct name of the gem in your code. For example, using the older rrd-ffi gem:
# use sudo if you're installing it to the system,
# but I would strongly recommend a ruby version
# manager instead
gem install rrd-ffi
# in your Ruby class/module file
require "rrd"
For the gem you seem to be using, you have to compile the gem first to make it usable, and then ensure it's available in your Ruby $LOAD_PATH (or other gem lookup mechanism) before trying to require it. The error message you're seeing is basically telling you that a gem with that name is not available as called within any of the standard lookup locations.
Again, I'd suggest reading the build documentation for your gem, and then seeing if you can install it as part of a Bundler bundle, RVM gemset, or other non-system approach if you can. Otherwise, follow the directions for the rrdruby tool, which is not available as a standard Rubygems.org gem, in order to make it available before trying to require it.
Beware of Outdated or Non-Standard Gems
Most of the RRD gems I found were quite old; most were 7-8 years old or older, so their compatibility with current Rubies is potentially suspect. The gem-builder you're using is newer, but doesn't seem to be designed as a standard gem, so you need to build it and install it in a suitable lookup path before it can be required. Installing gems as system gems is almost always a bad idea, so I'd strongly recommend building it from source and using a ruby version manager rather than following the rrdtool author's atypical suggestions. YMMV.

ruby - equivalent of `gem open` for core libraries

I can gem open #{gem_name} (command line) to see the source of installed gems. But how do I view the source of e.g. openssl which is in ruby core?
(Without going to the github repo... is there a command to view it locally?)
There isn't one. The reason most probably is that gems shipped with Ruby aren't treated in a different way than the core code. That said, the libraries are located under ext/.
If you want to find specific code (assuming it's Ruby and not C), you can always do
foo.method(:bar).source_location
Foo.instance_method(:bar).source_location

All Ruby documentation offline with yard

If I want see documentation on my gems I can do:
yard server --gems
How can I see the documentation of Ruby's standard library?
You have to
download the Ruby code archive and extract it into a directory,
run yardoc *.c (that will generate the core documentation),
2a. run yardoc . (that will generate the stdlib documentation but will take a lot of time),
run yard server.
(from http://gnuu.org/2010/10/13/local-copies-of-documentation/)

Generating RDOCs for locally installed gems

I am trying to contribute to a gem I recently took interest in - Nesta. The developer has done a great job in creating one of the lightest, thinest CMSs you can find and I want to document it. I have read through the code and commented on a few methods to the best of my knowledge.
However, I seek to test this out locally by calling gem server and seeing the changes on my machine before pushing it online.
Things I have tried:
Manual edit.
Documented the file.
Fired up gem server.
Using the gem tool.
Documented the file.
Ran gem rdoc nesta --rdoc
Restarted gem server
All to no avail. Please help.
Thank you.
You can preview generated html pages without installing a modified version of the gem on your machine. Add this to nesta's Rakefile:
require 'rake/rdoctask'
Rake::RDocTask.new('doc') do |i|
i.rdoc_files = FileList['lib/**/*']
end
and type rake doc. Then view generated html/index.html file.
Are you sure you've installed the version that you've modified, not the original version?
If you've installed the modified version, but have forgotten to install the rdoc, see Can you install documentation for existing gems?

Why is ri on Windows returning nothing?

When I type ri at the command prompt it returns nothing:
Classes and Modules known to ri:
How do I set this up properly?
Many thanks.
You can type gem rdoc --all --overwrite to have gem recreate ri and rdocs for all gems.
You don't say what version of Ruby you have installed, but 1.8.7 seemed to have problems remembering whether it had docs for the core and standard libraries. There was a gem called something like core-data that helped. If I can remember the real name I'll update this.
1.9.2 is better about its docs but I've seen times where I have to force the rebuild using the command above. A gem can act up, causing RDoc to puke, which ends up keeping all the docs from being generated so watch its progress and compare it to what gem list outputs as a sanity check. If that happens I have a shell script I use to walk through all the gems and rebuild their docs one by one. It's an easy piece of code to write and steps around the problem of a single gem killing the processing of everything.
I think you don't have the path to your ruby install folder in your PATH variable.
You have to do it to be allowed to launch ri in your command prompt.
Otherwise you can use the entire path : C:\Ruby\bin\ri.bat

Resources