-
How Rice Works
Posted on February 23rd, 2010 No commentsRice is one impressive piece of software. I highly doubt I could have written this from scratch (and for that I give Paul Brannan huge accolades for his work) but after working with and on this library for at least a year I probably could. Now that lead maintainership has been passed on to me, I’d like to take some time to explain exactly how Rice works, how one can dive in and help develop this library, and what my plans are for the near future as I work to make Rice and the rb++ suite; a full and proper replacement for SWIG when wrapping C++ libraries into Ruby (if you’re wrapping a pure C library, I highly recommend Ruby-FFI, though Rice will work).
So with that, I’m putting together this post to help clarify exactly how the various parts of Rice work together, how the entire process flows and more importantly helping anyone who’s wanting to learn and work on Rice with a solid starting point (or at least officially crooked). After reading this, anyone should be able to understand the various classes in Rice, and have an idea on where certain functionality lives when looking to add features, or address any bugs. So with that, we’ll start at the top.
-
Embedding IRB into your Ruby application
Posted on April 2nd, 2009 1 commentA feature I realized would be very helpful to have in rb++ is a debugging console. Basically, I wanted the ability to drop into an irb session and have available to me the internals of rb++ and rbgccxml, all set up for the sources I’ve specified for the given extension.
Turns out, this is a lot harder to figure out than it would initially seem. The irb code is quite complex and nothing there is documented in any way shape or form. Also, searches around the Internet came back with results that were some six years old, and while helpful, did not pertain to my particular case.
Then I remembered that ruby-debug does exactly what I’m looking for. A quick glance in that code got me the code snippet I needed.
require 'irb' module IRB # :nodoc: def self.start_session(binding) unless @__initialized args = ARGV ARGV.replace(ARGV.dup) IRB.setup(nil) ARGV.replace(args) @__initialized = true end workspace = WorkSpace.new(binding) irb = Irb.new(workspace) @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC] @CONF[:MAIN_CONTEXT] = irb.context catch(:IRB_EXIT) do irb.eval_input end end end
And it’s use is quite simple. When you want to drop into an irb session, you simply do
IRB.start_session(binding)
and you will have a code prompt with all data available at your finger-tips.
You use this feature in rb++ as follows:
ruby your_extension_file.rb console
From there, start playing around with the parsed source tree using either @parser or self.namespace to get started.

