Skip to content
This repository has been archived by the owner on Jul 22, 2018. It is now read-only.

Extending Ruby with Ruby

benjaminoakes edited this page Sep 11, 2012 · 13 revisions

Presenter: Michael Fairley

Abstract

Other programming languages have powerful features that are often enviable while working in Ruby: Python’s function decorators, Scala’s partial evaluation, and Haskell’s lazy evaluation, among others. Fortunately, Ruby’s metaprogramming facilities give us the ability to add these features to Ruby ourselves, without the need for the core language to be changed.

This talk will walk through adding simple (yet functional) versions of the previously mentioned features to Ruby, using Ruby, and discuss the dos and don’ts of responsible Ruby metaprogramming.

Notes

Method Decorators

Like function decorators (@memoize) in Python. Example from the README:

class Math
  extend MethodDecorators

  +Memoized
  def fib(n)
    if n <= 1
      1
    else
      fib(n - 1) * fib(n - 2)
    end
  end
end

Partial Application

An attempt at adding Scala-like syntax to Ruby. Example in Scala:

List(1, 2, 3).reduce(_ + _ * 2)

Lazy Evaluation

Haskell doesn't evaluate functions until their results are needed. He makes a Lazy class for Ruby to do this same type of thing (which can be used as a method decorator, of course).

External Links

A crowd-sourced conference wiki!
Working together is better. :)




Clone this wiki locally