Impresszum Help Sales ÁSZF Panaszkezelés DSA

Offline ruby-core and stdlib documentation with YARD

A short howto on creating a working offline Ruby documentation, including the ruby-core and stdlib, using the YARD gem. The original post here is 3 years old, and it was missing some instructions that took me 30 minutes googling and documentation reading.

I chose to generate the offline documentation from the Ruby source code itself. YARDoc can generate HTML pages along its own document format so you can decide in what format you want to browse the Ruby document pages. The OS is Linux and I have the most recent stable Ruby version (2.0.0-p247).

Install YARD:

$ gem install yard

Download the Ruby language source code and extract it (mine is ruby-2.0.0-p247 MRI but can be any version, although documentation quality might vary):

$ wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz
$ tar xzvf ruby-2.0.0-p247.tar.gz
$ cd ruby-2.0.0-p247

Build the core documentation:

$ yardoc *.c

YARDoc will create a ".yardoc" folder by default (surprise!), that contains the YARD format and a "doc" folder where it puts the HTML pages.

$ yardoc -b .yardoc-stdlib -o doc-stdlib

Here YARDoc will create a ".yardoc-stdlib" folder for its own format and a "doc-stdlib" for the HTML pages. And we're done!

Now you can go into one of those HTML folders and load 'index.html' into your browser, however index.html is not the real starting page for the framed version you might got used to. Index.html starts with a japanese language page where you need to click "Index" or "frames" to get to the familiar looking RubyDoc pages.

Or, let's start the YARD server:

$ yard server -m ruby-core2.0 .yardoc stdlib .yardoc-stdlib

"-m" tells YARD to load multiple documents, "ruby-core2.0" and "stdlib" are just screen names. Navigate your browser to http://localhost:8808 and you will see them popping up in a list.

Happy browsing offline.

0 Tovább

Ruby gems error: "Could not find a valid gem 'redcarpet' (= 0) in any repository ERROR: Possible alternatives: redcarpet"

Our company has moved, and we got a spectacular proxy installed at the new place, causing some chaos. Not only I had to reconfigure my Windows, I spent 2 hours to figure out how to use that proxy from a VirtualBoxed Debian. I had to supply my username and password on a command line to 'curl' or 'wget', that's for security. Setting system-wide proxy in $HTTP_PROXY env variable, also with my user/pass.

My first 'gem install' failed as it did not use the proxy. Configured it with the --http-proxy argument, it finally worked well.

Then I got home, no proxies, no whatever, just working network. A 'gem update' and a 'gem update --system' ran without error, but the next 'gem install'-s failed with a magic error:

> gem install redcarpet
WARNING:  Error fetching data: SocketError: getaddrinfo: Name or service
not known (http://rubygems.org/latest_specs.4.8.gz)
ERROR:  Could not find a valid gem 'redcarpet' (>= 0) in any repository
ERROR:  Possible alternatives: redcarpet

WTH? Gem install fails for a gem and immediately suggests the same gem?

Checked for proxy, none. Environment variable, none, there was no proxy set anywhere. Then I accidentally checkhed the 'gem install' doc:

-p, --[no-]http-proxy [URL]      Use HTTP proxy for remote operations

Err, why would it have a [no] prefix? If I don't want to use a proxy, I simply don't set it, right? Not right. Gem install remembers that I was using a proxy and tries to use it in subsequent requests.

Setting --no-http-proxy solved the problem.

Lesson learned: 'gem install' remembers if it was once run with --http-proxy parameter. Subsequent 'gem install' will use the same proxy regardless its availability.

0 Tovább

Ruby gem dependency FTW

  • simple_memoize gem uses jeweler
  • jeweler gem uses rcov
  • rcov gem cannot run under Ruby 1.9

Welcome to fail!

0 Tovább

Compacting non-contiguous data in Ruby arrays (an Array.uniq replacement)

In Ruby, uniq is great for clearing duplicate values from an Array. However it clears every duplication throughout the array, no matter where it is located.

irb(main):001:0> a = [1,1,1,3,3,5,7,7,7,7,7,1,1,1,3,3,3]
=> [1, 1, 1, 3, 3, 5, 7, 7, 7, 7, 7, 1, 1, 1, 3, 3, 3]
irb(main):002:0> a.uniq
=> [1, 3, 5, 7]

 

That's not what I want. I want the data locally uniq-ed, so that I'd get [1, 3, 5, 7, 1, 3] as if each contigous block of data were shrinked to exactly one element.

require 'pp'
  a, b = [1,1,1,3,3,5,7,7,7,7,7,1,1,1,3,3,3], []
  a.each {|x| if a[x]!=b.last then b.push(a[x]) end}
  pp b

 

This operation won't destroy 'a' therefore the a.each... line cannot be executed more than once without first clearing the target array, as it would push the data again into 'b'.

 

Update: Shoot! Enumerable#chunk - introduced in Ruby 1.9.2 - just does the same, so it is no use to reinvent the wheel.

0 Tovább

Ruby ARGV, OptionParser

0 Tovább

Ciklus performancia Rubyban

Maradék szabadidőmben ismét haszontalan dolgokkal kezdtem el foglalkozni, mint pl. a jó öreg Mandelbrot és Julia halmazok. Mivel a Ruby nyelvvel is most ismerkedem, remek alkalomnak tűnt a kettőt kombinálni.

Aztán belefutottam ebbe: http://shootout.alioth.debian.org/u64/performance.php?test=mandelbrot

Azt sejtettem, hogy a Ruby nem a legjobb választás a sima matematikai problémák megoldására - arra továbbra is a legjobb a C vagy a bátrabbaknak az Assembly - de az, hogy ilyen durván lassú legyen, azért nem gondoltam.

0 Tovább

/dev/random

blogavatar

Phasellus lacinia porta ante, a mollis risus et. ac varius odio. Nunc at est massa. Integer nis gravida libero dui, eget cursus erat iaculis ut. Proin a nisi bibendum, bibendum purus id, ultrices nisi.

Utolsó kommentek