Skip to main content

rb_undef_method

Function rb_undef_method 

Source
pub unsafe extern "C" fn rb_undef_method(
    klass: VALUE,
    name: *const c_char,
)
Expand description

Defines an undef of a method. – What?

In ruby, there are two separate concepts called “undef” and “remove_method”. The thing you imagine when you “un-define” a method is remove_method. This one on the other hand is masking of a previous method definition. Suppose for instance:

class Foo
  def foo
  end
end

class Bar < Foo
  def bar
    foo
  end
end

class Baz < Foo
  undef foo            # <--- (*1)
end

This undef foo at (*1) must not eliminate Foo#foo, because that method is also used from Bar#bar. So instead of physically executing the target method, undef inserts a special filtering entry to the class (Baz this case). That entry, when called, acts as if there were no methods at all. But the original can still be accessible, via ways like Bar#bar above.

§@param[out] klass The class to insert an undef. @param[in] name Name of the undef. @exception rb_eTypeError klass is a non-module. @exception rb_eFrozenError klass is frozen. @see rb_remove_method

Generated by rb-sys for Ruby mri-x86_64-linux-gnu-3.3.8