Class: Module
- Defined in:
- lib/y_support/unicode.rb,
lib/y_support/core_ext/module/misc.rb,
lib/y_support/typing/module/typing.rb
Instance Method Summary collapse
-
#attr_accessor_with_default(*symbols, &block) ⇒ Object
(also: #attr_accessor_w_default)
I didn’t write this method by myself.
-
#autoreq(*symbols, descending_path: '..', ascending_path_prefix: 'lib') ⇒ Object
Further automation of soon-to-be-deprecated #autorequire.
-
#compliance ⇒ Object
Compliance (declared compliance + ancestors).
-
#complies?(other_module) ⇒ Boolean
Compliance inquirer (declared compliance + ancestors).
-
#declare_compliance!(other_module) ⇒ Object
Declaration of module / class compliance.
-
#declared_compliance ⇒ Object
Declared compliance getter.
-
#declares_compliance?(other_module) ⇒ Boolean
Declared complience inquirer.
Instance Method Details
#attr_accessor_with_default(*symbols, &block) ⇒ Object Also known as: attr_accessor_w_default
I didn’t write this method by myself.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/y_support/core_ext/module/misc.rb', line 24 def attr_accessor_with_default *symbols, &block raise ArgumentError, 'Block with default value required!' unless block symbols.each { |ß| module_eval { define_method "#{ß}=" do |arg| instance_variable_set "@#{ß}", arg end define_method ß do singleton_class.class_eval { attr_reader ß } if instance_variables.include? "@#{ß}".to_sym then instance_variable_get "@#{ß}" else instance_variable_set "@#{ß}", block.call end end } } end |
#autoreq(*symbols, descending_path: '..', ascending_path_prefix: 'lib') ⇒ Object
Further automation of soon-to-be-deprecated #autorequire.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/y_support/core_ext/module/misc.rb', line 6 def autoreq( *symbols, descending_path: '..', ascending_path_prefix: 'lib' ) require 'active_support/core_ext/string/inflections' namespace = self.name namespace_path = namespace.underscore namespace_chain = namespace.split "::" ascending_path = ascending_path_prefix + '/' + namespace_path symbols.map( &:to_s ).each { |ς| next if ς.strip.empty? camelized_ß = ς.camelize.to_sym path = './' + [ descending_path, ascending_path, ς ].join( '/' ) autoload camelized_ß, path } end |
#compliance ⇒ Object
Compliance (declared compliance + ancestors).
22 23 24 |
# File 'lib/y_support/typing/module/typing.rb', line 22 def compliance ( declared_compliance + ancestors ).uniq end |
#complies?(other_module) ⇒ Boolean
Compliance inquirer (declared compliance + ancestors).
8 9 10 11 |
# File 'lib/y_support/typing/module/typing.rb', line 8 def complies?( other_module ) other_module.aT_kind_of Module, "other module" compliance.include? other_module end |
#declare_compliance!(other_module) ⇒ Object
Declaration of module / class compliance.
36 37 38 39 40 41 |
# File 'lib/y_support/typing/module/typing.rb', line 36 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.
28 29 30 31 32 |
# File 'lib/y_support/typing/module/typing.rb', line 28 def declared_compliance ( ( @declared_compliance || [] ) + ancestors.map { |a| a.instance_variable_get( :@declared_compliance ) || [] }.reduce( [], :+ ) ).uniq end |
#declares_compliance?(other_module) ⇒ Boolean
Declared complience inquirer.
15 16 17 18 |
# File 'lib/y_support/typing/module/typing.rb', line 15 def declares_compliance?( other_module ) other_module.aT_kind_of Module, "other module" declared_compliance.include? other_module end |