First we set up the Ruby engine.

library(knitr)
library(runr)
rb = proc_ruby(22222)
rb$start()
knit_engines$set(ruby = function(options) {
    knitr:::wrap(rb$exec(options$code), options)
})
opts_chunk$set(engine='ruby')

Test print:

hello = 'Hello!'
print hello
## Hello!

Test a method:

def mean(arr)
  arr.inject(:+).to_f / arr.length
end
print mean((1..5).to_a)
## 3.0

Do not forget to shut it down in the end.

rb$stop()