From: Florian Gross Date: 2007-07-12T04:22:18+09:00 Subject: Re: to_str conversions and exceptions On Jul 11, 7:35 pm, "John Lam (CLR)" wrote: > Silly question of the day: > > Does Ruby use respond_to? to test for the existence of a to_str method in methods like String#[int, int] = str? IOW does it do something like: You will actually need to be careful though. You actually need to call respond_to?() in Ruby. This means that overriding respond_to?() in Ruby is possible. That is important because of objects like DRbObject that delegate method calls across the network. Here's a sample: obj = Object.new def obj.respond_to?(*a) p [:respond_to?, *a] return true end def obj.method_missing(*a) p [:method_missing, *a] return "hello" end str = "hi world" str[0,2] = obj # >> [:respond_to?, :to_str] # >> [:method_missing, :to_str] str # => "hello world" And yup, this is missing from Rubinius specs. Thank you for making me notice that. :)