Nope.

Josh Adams (@isotope11) started IRuby as a weekend project, and Daniel Mendler (@minad) has taken it over in the last few weeks, adding buckets of awesome.

This notebook is adapted from https://github.com/minad/iruby

In [1]:
puts `showipconfig ruby`

config for: /Users/minrk/.ipython/profile_ruby/ipython_config.py

KernelManager
  .kernel_cmd = [
     "iruby", 
     "kernel", 
     "{connection_file}"
    ]

config for: /Users/minrk/.ipython/profile_ruby/ipython_notebook_config.py

NotebookApp
  .port = 8988


In [2]:
puts ARGV
["kernel", "/Users/minrk/.ipython/profile_ruby/security/kernel-478927a5-cd0f-4583-97c9-f709c4c73da0.json"]

In [3]:
puts 'Hello, world!'
Hello, world!

In [4]:
$stderr.puts 'Error!'
Error!

The last computed result is returned.

In [5]:
Math.sqrt(2)
Out[5]:
1.4142135623730951

This works even for images.

In [6]:
File.open('img/ruby.svg')
Out[6]:
image/svg+xml

Display

IRuby provides a method to display objects IRuby.display and methods to create \(\LaTeX\) and HTML representations.

In [7]:
IRuby.display '<b style="color:green">Hello, world!</b>', mime: 'text/html'
Out[7]:
Hello, world!
In [8]:
IRuby.html '<b style="color:blue">I&apos;m Blue</b>'
Out[8]:
I'm Blue

\(\LaTeX\) is rendered using MathJax.

In [9]:
IRuby.display IRuby.latex <<-'TEX'
\begin{eqnarray}
\nabla \times \vec{\mathbf{B}} &
    - \frac{1}{c} \frac{\partial\vec{\mathbf{E}}}{\partial t} 
    & = & \frac{4 \pi}{c} \vec{\mathbf{j}} \\
\nabla \cdot \vec{\mathbf{E}} && = & 4 \pi \rho \\
\nabla \times \vec{\mathbf{E}} &
    + \frac{1}{c} \frac{\partial\vec{\mathbf{B}}}{\partial t}
    & = & \vec{\mathbf{0}} \\
\nabla \cdot \vec{\mathbf{B}} && = & 0 
\end{eqnarray}
TEX

IRuby.math('F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx')
Out[9]:
\begin{eqnarray} \nabla \times \vec{\mathbf{B}} & - \frac{1}{c} \frac{\partial\vec{\mathbf{E}}}{\partial t} & = & \frac{4 \pi}{c} \vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} && = & 4 \pi \rho \\ \nabla \times \vec{\mathbf{E}} & + \frac{1}{c} \frac{\partial\vec{\mathbf{B}}}{\partial t} & = & \vec{\mathbf{0}} \\ \nabla \cdot \vec{\mathbf{B}} && = & 0 \end{eqnarray}
Out[9]:
$$F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx$$

Arrays and Hashes can be printed as HTML tables.

In [10]:
IRuby.display IRuby.table([[1,2],[3,4,5]])
IRuby.display IRuby.table({a:[11,12,13,14],b:[21,22,23],c:[31,32,33,34]})
Out[10]:
12
345
Out[10]:
a11121314
b212223
c31323334

Integration with Ruby gems

Pry

Pry is an enhanced Ruby REPL. It will be automatically used by IRuby if available. You can use the code browsing utilities for example.

In [11]:
ls File
constants: ALT_SEPARATOR  Constants  PATH_SEPARATOR  Separator  SEPARATOR  Stat
IO.methods: 
  binread   console      for_fd   new   pipe   read       select   try_convert
  binwrite  copy_stream  foreach  open  popen  readlines  sysopen  write      
File.methods: 
  absolute_path  delete            extname     lchmod  readable?       size      truncate         zero?
  atime          directory?        file?       lchown  readable_real?  size?     umask          
  basename       dirname           fnmatch     link    readlink        socket?   unlink         
  blockdev?      executable?       fnmatch?    lstat   realdirpath     split     utime          
  chardev?       executable_real?  ftype       mtime   realpath        stat      world_readable?
  chmod          exist?            grpowned?   owned?  rename          sticky?   world_writable?
  chown          exists?           identical?  path    setgid?         symlink   writable?      
  ctime          expand_path       join        pipe?   setuid?         symlink?  writable_real? 
File#methods: atime  chmod  chown  ctime  flock  lstat  mtime  path  size  to_path  truncate


RMagick

Magick::Image objects are automatically displayed inline as PNG.

In [12]:
require 'RMagick'

img = Magick::Image.new(240, 300)
gc = Magick::Draw.new
gc.fill('#FFAA00')

x = 120
y = 32.5
gc.polygon(x,    y,     x+29, y+86,  x+109, y+86,
           x+47, y+140, x+73, y+226, x,     y+175,
           x-73, y+226, x-47, y+140, x-109, y+86,
           x-29, y+86)

gc.draw(img)

img
Out[12]:

Rubyvis

Rubyvis objects are automatically displayed inline as SVG.

In [13]:
require 'rubyvis'
    
Rubyvis::Panel.new do 
  width 400
  height 240
  bar do
    data [1, 1.2, 1.7, 1.5, 0.7, 0.3]
    width 50
    height {|d| d * 120}
    bottom(0)
    left {index * 55}
  end
end
Out[13]:

Gruff

Gruff::Base objects are automatically displayed inline as PNG.

In [14]:
require 'gruff'
g = Gruff::Line.new
g.title = 'Gruff Example'
g.data :Jimmy, [25, 36, 86, 39, 25, 31, 79, 88]
g.data :Charles, [80, 54, 67, 54, 68, 70, 90, 95]
g.data :Julie, [22, 29, 35, 38, 36, 40, 46, 57]
g.data :Jane, [95, 95, 95, 90, 85, 80, 88, 100]
g.data :Philip, [90, 34, 23, 12, 78, 89, 98, 88]
g.data :Arthur, [5, 10, 13, 11, 6, 16, 22, 32]
g
Out[14]:

But wait, there's more!