@SuppressWarnings("unchecked")
    public static <T> T deep(final T input) {
        if (input instanceof Map<?, ?>) {
            return (T) deepMap((Map<?, ?>) input);
        } else if (input instanceof List<?>) {
            return (T) deepList((List<?>) input);
        } else if (input instanceof RubyString) {
            // new instance but sharing ByteList (until either String is modified)
            return (T) ((RubyString) input).dup();
        } else if (input instanceof Collection<?>) {
            throw new ClassCastException("unexpected Collection type " + input.getClass());
        }

        return input;
    }
@Test
    public void testRubyStringCloning() {
        String javaString = "fooBar";
        RubyString original = RubyString.newString(RubyUtil.RUBY, javaString);

        RubyString result = Cloner.deep(original);
        // Check object identity
        assertNotSame(original, result);
        // Check string equality
        assertEquals(original, result);

        assertEquals(javaString, result.asJavaString());
    }