-
Notifications
You must be signed in to change notification settings - Fork 25
Extending Ruby with Ruby
Presenter: Michael Fairley
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.
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
An attempt at adding Scala-like syntax to Ruby. Example in Scala:
List(1, 2, 3).reduce(_ + _ * 2)
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).
- Slides (has speaker notes)
-
method_decorators
A crowd-sourced conference wiki!
Working together is better. :)
- Speakers, for example:
- Recent Conferences
- Software
- Offline Access
- Contributors (More than 50!)
- Code Frequency