From: Simon Strandgaard Date: 2004-03-23T04:34:39+09:00 Subject: Re: forwardable.rb On Tue, 23 Mar 2004 02:15:18 +0900, Dave Thomas wrote: > I'm being dense today, but can anyone think of a real-world application > of SingleForwardable? I keep trying to come up with examples, but I > haven't yet discovered any that aren't better written as methods inside > the class itself. > The only usage I can think of is unittesting. Imagine that the Values class is some class that we didn't wrote and that we somehow needs to populate it with data. server> ruby a.rb # server> expand -t2 a.rb class Values def initialize @values = [] end attr_reader :values end # imagine that this is a testcase, located in a # different file. require 'forwardable' v = Values.new v.extend SingleForwardable v.def_delegator("@values", :<<, "append") v.append(1) v.append(2) p v server> I don't know if this can be useful.. some kind of mockobject is probably better to use in this case. -- Simon Strandgaard