Gregory Seidman
3/31/2006 8:44:00 PM
On Sat, Apr 01, 2006 at 12:38:43AM +0900, baumanj@gmail.com wrote:
} ara.t.howard@noaa.gov wrote:
} > On Fri, 31 Mar 2006, Christian Neukirchen wrote:
} > > if a.kind_of? Boolean
} > >
} > > case y
} > > when Integer
} > > when Boolean
} > > end
}
} What kind of scenarios would you want to use such a construct? It seems
} to me not very rubyish to be switching based on the class of an object.
} As I understand it, the more conventional way to deal with potentially
} diverse argument types is to use the respond_to? method. This keeps the
} door open for duck typing.
[...]
The most obvious answer is that it is needed for various kinds of
serialization. I wrote something like this just the other day. I needed to
do XML-RPC serialization (yes, I know there is XML-RPC support in the
standard library, but I needed something slightly different that was easier
to do by hand), so I needed to know what kind of value I was serializing.
--Greg