APIdock / Ruby
/
Browse About
method

module_exec

v1_9_3_125 - Show latest stable - Class: Module
module_exec(*args)
public

Evaluates the given block in the context of the class/module. The method defined in the block will belong to the receiver.

class Thing
end
Thing.class_exec{
  def hello() "Hello there!" end
}
puts Thing.new.hello()

produces:

Hello there!
VALUE
rb_mod_module_exec(int argc, VALUE *argv, VALUE mod)
{
    return yield_under(mod, mod, rb_ary_new4(argc, argv));
}

Related methods

  • Instance methods
  • <
  • <=
  • <=>
  • ==
  • ===
  • >
  • >=
  • ancestors
  • autoload
  • autoload?
  • class_eval
  • class_exec
  • class_variable_defined?
  • class_variable_get
  • class_variable_set
  • class_variables
  • const_defined?
  • const_get
  • const_missing
  • const_set
  • constants
  • freeze
  • include?
  • included_modules
  • infect_an_assertion
  • infect_with_assertions
  • initialize_copy
  • instance_method
  • instance_methods
  • method_defined?
  • module_eval
  • module_exec
  • name
  • private_class_method
  • private_instance_methods
  • private_method_defined?
  • protected_instance_methods
  • protected_method_defined?
  • psych_yaml_as
  • public_class_method
  • public_instance_method
  • public_instance_methods
  • public_method_defined?
  • rake_extension
  • rake_original_const_missing
  • remove_class_variable
  • to_s
  • yaml_as
  • Class methods
  • constants
  • nesting
  • new
  • Private methods
  • privatealias_method
  • privateappend_features
  • privateattr
  • privateattr_accessor
  • privateattr_reader
  • privateattr_writer
  • privatedefine_method
  • privateextend_object
  • privateextended
  • privateinclude
  • privateincluded
  • privatemethod_added
  • privatemethod_removed
  • privatemethod_undefined
  • privatemodule_function
  • privateprivate
  • privateprotected
  • privatepublic
  • privateremove_const
  • privateremove_method
  • privateundef_method
APIdock API Documentation Browser

© 2026 APIdock