How sciruby/iruby works
Below are detailed steps and guidelines tailored to IRuby’s structure:
Main Components
• Jupyter Frontend: This is the external environment where users interact with notebooks. (This isn’t part of IRuby’s source, but it’s a critical external actor.)
• Application Layer (lib/iruby/application.rb): This likely handles the high-level application logic and the lifecycle of the IRuby kernel.
• Core Kernel and Session Management: For example, lib/iruby/kernel.rb and lib/iruby/session.rb along with the session adapters (ffirzmq, cztop, etc.) represent the messaging and session logic to connect to Jupyter.
• Backend Processing: The “backend” for Ruby code execution, where you see files like lib/iruby/backend.rb and the differentiation between PlainBackend and PryBackend.
• Communication (Comm): The module in lib/iruby/comm.rb is responsible for the interactive messaging system that communicates with Jupyter’s front-end.
• Input Widgets: The lib/iruby/input directory (and its various widget components) represents the abstraction for handling user inputs coming from notebook widgets.
• Asset Management: The assets directory under lib/iruby/assets (containing CSS and JS files) serves to customize or support the Jupyter interface.
• Utilities and Error Handling: Modules like logger, formatter, display, and error handling code provide support functions that glue the system together.
Relationships and Interactions
• The “Application & Core” block (including Application, Kernel, and Logger).
• The “Session & Communication” block (including Session, Session Adapter layers, and Comm) that interacts with ZeroMQ (via ffi-rzmq or cztop as indicated by their directories and the README).
• The “Backend” block showing the exchange between Ruby’s native IRB (or Pry) and the kernel code.
• The “Input Widget” block (all components in lib/iruby/input) responsible for managing interactive UI elements.
• The “Assets” block (CSS/JS) that supports any web-based interface customizations.
• Incoming code or widget actions pass into the communication (Comm) and session modules.
• The kernel then delegates code execution onto the selected backend (PlainBackend with IRB, or PryBackend if switched).
• Results are then formatted (using Formatter or Display) and sent back to the front-end.
Architectural Patterns
• Layered Communication: With session adapters (ffirzmq, cztop) abstracting the underlying ZeroMQ communication, represent an abstraction layer between IRuby’s core and the external messaging system.
Relevant Technologies and Dependencies
• External dependencies such as ZeroMQ (libzmq, ffi-rzmq, and optionally cztop) used by session adapters.
• Mention that Jupyter (not part of the repository but fundamental to IRuby’s functionality) is the primary frontend.
• That IRuby leverages Ruby’s runtime (IRB or Pry) for executing code.