johnbender.us

recent / categories / archives

Posted
28 October 2009 @ 7pm

Tagged
ruby

Ruby Cons

I think technically this counts as an application of my readings from Algebra of Programming. Satisfied. class Cons include Enumerable attr_accessor :child, :value def self.[](value, child=:empty) new(value, child) end def initialize(value, child) @value, @child = value, child end def each x = self while( x != :empty) yield x x = x.child end end end [...]