parents

parents() Instance Public methods Returns all the parents of this module according to its name, ordered from nested outwards. The receiver is not contained within the result. module M module N end end X = M::N M.parents # => [Object] M::N.parents # => [M, Object] X.parents # => [M, Object]

parent_name

parent_name() Instance Public methods Returns the name of the module containing this one. M::N.parent_name # => "M"

parent

parent() Instance Public methods Returns the module which contains this one according to its name. module M module N end end X = M::N M::N.parent # => M X.parent # => M The parent of top-level and anonymous modules is Object. M.parent # => Object Module.new.parent # => Object

mattr_writer

mattr_writer(*syms) Instance Public methods Defines a class attribute and creates a class and instance writer methods to allow assignment to the attribute. module HairColors mattr_writer :hair_colors end class Person include HairColors end HairColors.hair_colors = [:brown, :black] Person.class_variable_get("@@hair_colors") # => [:brown, :black] Person.new.hair_colors = [:blonde, :red] HairColors.class_variable_get("@@hair_colors") # => [:blonde, :red] If you want to op

mattr_reader

mattr_reader(*syms) Instance Public methods Defines a class attribute and creates a class and instance reader methods. The underlying the class variable is set to nil, if it is not previously defined. module HairColors mattr_reader :hair_colors end HairColors.hair_colors # => nil HairColors.class_variable_set("@@hair_colors", [:brown, :black]) HairColors.hair_colors # => [:brown, :black] The attribute name must be a valid method name in Ruby. module Foo mattr_reader :"1

mattr_accessor

mattr_accessor(*syms, &blk) Instance Public methods Defines both class and instance accessors for class attributes. module HairColors mattr_accessor :hair_colors end class Person include HairColors end Person.hair_colors = [:brown, :black, :blonde, :red] Person.hair_colors # => [:brown, :black, :blonde, :red] Person.new.hair_colors # => [:brown, :black, :blonde, :red] If a subclass changes the value then that would also change the value for parent class. Simila

foo

foo() Instance Public methods

deprecate

deprecate(*method_names) Instance Public methods deprecate :foo deprecate bar: 'message' deprecate :foo, :bar, baz: 'warning!', qux: 'gone!' You can also use custom deprecator instance: deprecate :foo, deprecator: MyLib::Deprecator.new deprecate :foo, bar: "warning!", deprecator: MyLib::Deprecator.new Custom deprecators must respond to deprecation_warning(deprecated_method_name, message, caller_backtrace) method where you can implement your custom warning behavior. class MyLib::D

delegate

delegate(*methods) Instance Public methods Provides a delegate class method to easily expose contained objects' public methods as your own. Options :to - Specifies the target object :prefix - Prefixes the new method with the target name or a custom prefix :allow_nil - if set to true, prevents a NoMethodError to be raised The macro receives one or more method names (specified as symbols or strings) and the name of the target object via the :to option (also a symbol or string

cattr_writer

cattr_writer(*syms) Instance Public methods Alias for: mattr_writer