include?

mod.include?(module) â true or false Instance Public methods Returns true if module is included in mod or one of mod's ancestors. module A end class B include A end class C < B end B.include?(A) #=> true C.include?(A) #=> true A.include?(A) #=> false

included_modules

mod.included_modules â array Instance Public methods Returns the list of modules included in mod. module Mixin end module Outer include Mixin end Mixin.included_modules #=> [] Outer.included_modules #=> [Mixin]

inspect

inspect() Instance Public methods Alias for: to_s

instance_method

mod.instance_method(symbol) â unbound_method Instance Public methods Returns an UnboundMethod representing the given instance method in mod. class Interpreter def do_a() print "there, "; end def do_d() print "Hello "; end def do_e() print "!\n"; end def do_v() print "Dave"; end Dispatcher = { "a" => instance_method(:do_a), "d" => instance_method(:do_d), "e" => instance_method(:do_e), "v" => instance_method(:do_v) } def interpret(

instance_methods

mod.instance_methods(include_super=true) â array Instance Public methods Returns an array containing the names of the public and protected instance methods in the receiver. For a module, these are the public and protected methods; for a class, they are the instance (not singleton) methods. With no argument, or with an argument that is false, the instance methods in mod are returned, otherwise the methods in mod and mod's superclasses are returned. module A def method1() end e

method_defined?

mod.method_defined?(symbol) â true or false Instance Public methods Returns true if the named method is defined by mod (or its included modules and, if mod is a class, its ancestors). Public and protected methods are matched. module A def method1() end end class B def method2() end end class C < B include A def method3() end end A.method_defined? :method1 #=> true C.method_defined? "method1" #=> true C.method_defined? "method2" #=> true C.method_d

module_eval

mod.module_eval {|| block } â obj Instance Public methods Evaluates the string or block in the context of mod, except that when a block is given, constant/class variable lookup is not affected. This can be used to add methods to a class. module_eval returns the result of evaluating its argument. The optional filename and lineno parameters set the text for error messages. class Thing end a = %q{def hello() "Hello there!" end} Thing.module_eval(a) puts Thing.new.h

module_exec

mod.module_exec(arg...) {|var...| block } â obj Instance Public methods 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!

name

mod.name â string Instance Public methods Returns the name of the module mod. Returns nil for anonymous modules.

private_class_method

mod.private_class_method(symbol, ...) â mod Instance Public methods Makes existing class methods private. Often used to hide the default constructor new. class SimpleSingleton # Not thread safe private_class_method :new def SimpleSingleton.create(*args, &block) @me = new(*args, &block) if ! @me @me end end