module Doubler def double self + self end end class String include Doubler # for a good time... # def method_missing x # self + x.to_s # end end class Name include Comparable attr_accessor :first, :last def initialize (first, last) @first = first @last = last end def <=> other ans = last <=> other.last return ans if ans != 0 first <=> other.first end end class BinaryTree include Enumerable attr_accessor :left, :data, :right def initialize(l, x, r) @left = l @data = x @right = r end # in section AB, we had left the method_missing on String trick above, # which caused problems in irb itself :( # # the following code is actually fine def each left.each { |x| yield x } unless left.nil? yield data right.each { |x| yield x } unless right.nil? end end