Class: Module
- Defined in:
- lib/y_support/unicode.rb,
lib/y_support/core_ext/module/misc.rb,
lib/y_support/core_ext/module/misc.rb,
lib/y_support/typing/module/typing.rb
Overview
y_support/unicode
also defines the following aliases:
-
★ – alias for include
-
ç for
class
in several method names
Instance Method Summary collapse
-
#chain(**hash, &block) ⇒ Object
Defines a set of methods by applying the block on the return value of another set of methods.
-
#compliance ⇒ Object
Compliance (declared compliance + ancestors).
-
#complies?(other_module) ⇒ Boolean
Compliance inquirer (declared compliance + ancestors).
-
#const_reset!(const, value) ⇒ Object
Redefines a constant without warning.
-
#const_set_if_not_defined(const, value) ⇒ Object
Sets a constant to a value if this has not been previously defined.
-
#declare_compliance!(other_module) ⇒ Object
Using this method, the receiver explicitly declares that its interface complies with another module (class).
-
#declared_compliance ⇒ Object
Declared compliance getter.
-
#declares_compliance?(other_module) ⇒ Boolean
Declared compliance inquirer.
Instance Method Details
#chain(**hash, &block) ⇒ Object
Defines a set of methods by applying the block on the return value of another set of methods. Accepts a hash of pairs { mapped_method_symbol => original_method_symbol } and a block which to chain to the original method result.
20 21 22 23 24 25 26 |
# File 'lib/y_support/core_ext/module/misc.rb', line 20 def chain **hash, &block hash.each_pair { |mapped_method_symbol, original_method_symbol| define_method mapped_method_symbol do |*args, &b| block.( send original_method_symbol, *args, &b ) end } end |
#compliance ⇒ Object
Compliance (declared compliance + ancestors).
19 20 21 |
# File 'lib/y_support/typing/module/typing.rb', line 19 def compliance ( declared_compliance + ancestors ).uniq end |
#complies?(other_module) ⇒ Boolean
Compliance inquirer (declared compliance + ancestors).
6 7 8 |
# File 'lib/y_support/typing/module/typing.rb', line 6 def complies?( other_module ) compliance.include? other_module.aT_kind_of( Module, "other module" ) end |
#const_reset!(const, value) ⇒ Object
Redefines a constant without warning.
10 11 12 13 |
# File 'lib/y_support/core_ext/module/misc.rb', line 10 def const_reset!( const, value ) send :remove_const, const if const_defined? const const_set( const, value ) end |
#const_set_if_not_defined(const, value) ⇒ Object
Sets a constant to a value if this has not been previously defined.
4 5 6 |
# File 'lib/y_support/core_ext/module/misc.rb', line 4 def const_set_if_not_defined( const, value ) const_set( const, value ) unless const_defined? const end |
#declare_compliance!(other_module) ⇒ Object
Using this method, the receiver explicitly declares that its interface complies with another module (class).
34 35 36 37 38 39 |
# File 'lib/y_support/typing/module/typing.rb', line 34 def declare_compliance! other_module other_module.aT_kind_of Module, "other module" return false if declared_compliance.include? other_module ( @declared_compliance ||= [] ) << other_module return true end |
#declared_compliance ⇒ Object
Declared compliance getter.
25 26 27 28 29 |
# File 'lib/y_support/typing/module/typing.rb', line 25 def declared_compliance ( ( @declared_compliance || [] ) + ancestors.map { |a| a.instance_variable_get( :@declared_compliance ) || [] }.reduce( [], :+ ) ).uniq end |
#declares_compliance?(other_module) ⇒ Boolean
Declared compliance inquirer.
12 13 14 15 |
# File 'lib/y_support/typing/module/typing.rb', line 12 def declares_compliance?( other_module ) other_module.aT_kind_of Module, "other module" declared_compliance.include? other_module end |