Using Ruby in Jupyter notebooks

As you may have already figured it out - I am a big fan of jupyter notebooks. In a previous post I showed you how to install the Go kernel for jupyter.

Today I will show you how to do the same for Ruby!

Before we start I assume you already have installed in your machine the following:

Note for installation using jupyterlabs follow this post from Dusty Candland.

Installing Ruby 2.7.1

For rbenv:

RUBY_CONFIGURE_OPTS="--enable-shared" rbenv install 2.7.1

Optional:

rbenv global 2.7.1

For RVM (not tested):

rvm install 2.7.1 -- --enable-shared

Homebrew

This will take a while so go for a coffee and relax…

brew install automake gmp libtool wget
brew install zeromq --HEAD
brew install czmq --HEAD

Update bash or zshrc

Add the following lines to either .zshrc or .bashrc

export LIBZMQ_PATH=$(brew --prefix zeromq)/lib
export LIBCZMQ_PATH=$(brew --prefix czmq)/lib

Install iRuby

gem install cztop
gem install iruby --pre
iruby register --force

You can know kick off jupyter notebook and a Ruby 2.7.1 option should be available when creating a new notebook.

ruby_jupyter

Let’s try it!!!

["A","B","C"].map(&:downcase)
["a", "b", "c"]
class Jupyter
  def self.hello
    puts "Hello from Jupyter"
  end
end
:hello
Jupyter.hello
Hello from Jupyter

Enjoy!!!

Comments

comments powered by Disqus