method_missing(m, *a, &b)
public
Try to forward all undefined methods to the handler, when a method is not
defined on the handler, send it to the contained string. Method_missing is
also responsible for making the bang! methods destructive.
Show source
def method_missing(m, *a, &b)
begin
if m.to_s =~ /^(.*)\!$/ && handler.respond_to?($1)
result = handler.send($1, @string, *a, &b)
if result == @string
result = nil
else
@string.replace result
end
elsif handler.respond_to?(m)
result = handler.send(m, @string, *a, &b)
else
result = @string.send(m, *a, &b)
end
rescue Handlers::EncodingError
@string.replace handler.tidy_bytes(@string)
retry
end
if result.kind_of?(String)
result.chars
else
result
end
end