    fn {{ name }}({{ signature }}) -> {{ return_type }} {
        let responds = self.rb_obj.respond_to("{{ name }}", false).unwrap_or(false);
        if !responds {
            return {{ default_result_expr }};
        }

{%- if has_args %}
        let result: Result<magnus::Value, magnus::Error> = self.rb_obj.funcall("{{ name }}", {{ args_tuple }});
{%- else %}
        let result: Result<magnus::Value, magnus::Error> = self.rb_obj.funcall("{{ name }}", ());
{%- endif %}

        match result {
            Err(_) => {{ default_result_expr }},
            Ok(val) => {
                // Hash with :custom key — e.g. { custom: '--- {text} ---' }
                if let Some(hash) = magnus::RHash::from_value(val) {
                    let ruby = unsafe { magnus::Ruby::get_unchecked() };
{%- for variant in payload_result_variants %}
                    if let Some(custom_val) = hash.get(ruby.to_symbol("{{ variant.wire_name }}")) {
                        return {{ return_type }}::{{ variant.name }}(custom_val.to_string());
                    }
{%- endfor %}
                }
                let s: String = val.to_string();
                match s.as_str() {
{%- for variant in unit_result_variants %}
                    "{{ variant.wire_name }}" => {{ return_type }}::{{ variant.name }},
{%- endfor %}
                    _ => {{ unknown_string_result_expr }},
                }
            }
        }
    }
