Skip to content

Instantly share code, notes, and snippets.

@rubyworks
rubyworks / roman_numeral.rb
Created March 2, 2010 17:03
RomanNumeral Class
# Work with Roman numerals just like normal Integers.
class RomanNumeral < Numeric
include Comparable
# The largest integer representable as a roman
# numerable by this module.
MAX = 3999
# Taken from O'Reilly's Perl Cookbook 6.23. Regular Expression Grabbag.
REGEXP = /^M*(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}|I[VX])$/i
@rubyworks
rubyworks / semaphore.rb
Created April 27, 2010 12:17
semaphore.rb
# = Semaphore
#
# Technically a semaphore is simply an integer variable which
# has an execution queue associated with it.
#
# Copyright (c) 2005 Fukumoto
class Semaphore
def initialize(initvalue = 0)