Sha256: 61db1578f526411fa3995ee4de1eb1c3b2a9353222dd27eed70d583ce3380e22

Contents?: true

Size: 1.05 KB

Versions: 47

Compression:

Stored size: 1.05 KB

Contents

#encoding: utf-8

class Module
  # === Support for typing by declaration

  # Compliance inquirer (declared compliance + ancestors).
  # 
  def complies?( other_module )
    other_module.aT_kind_of Module, "other module"
    compliance.include? other_module
  end

  # Declared complience inquirer.
  # 
  def declares_compliance?( other_module )
    other_module.aT_kind_of Module, "other module"
    declared_compliance.include? other_module
  end

  # Compliance (declared compliance + ancestors).
  # 
  def compliance
    ( declared_compliance + ancestors ).uniq
  end

  # Declared compliance getter.
  # 
  def declared_compliance
    ( ( @declared_compliance || [] ) + ancestors.map { |a|
        a.instance_variable_get( :@declared_compliance ) || []
      }.reduce( [], :+ ) ).uniq
  end

  # Declaration of module / class compliance.
  # 
  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
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
y_support-2.1.5 lib/y_support/typing/module/typing.rb
y_support-2.1.4 lib/y_support/typing/module/typing.rb
y_support-2.1.3 lib/y_support/typing/module/typing.rb
y_support-2.1.2 lib/y_support/typing/module/typing.rb
y_support-2.1.1 lib/y_support/typing/module/typing.rb
y_support-2.1.0 lib/y_support/typing/module/typing.rb
y_support-2.0.43 lib/y_support/typing/module/typing.rb
y_support-2.0.42 lib/y_support/typing/module/typing.rb
y_support-2.0.41 lib/y_support/typing/module/typing.rb
y_support-2.0.39 lib/y_support/typing/module/typing.rb
y_support-2.0.38 lib/y_support/typing/module/typing.rb
y_support-2.0.37 lib/y_support/typing/module/typing.rb
y_support-2.0.36 lib/y_support/typing/module/typing.rb
y_support-2.0.35 lib/y_support/typing/module/typing.rb
y_support-2.0.34 lib/y_support/typing/module/typing.rb
y_support-2.0.33 lib/y_support/typing/module/typing.rb
y_support-2.0.31 lib/y_support/typing/module/typing.rb
y_support-2.0.30 lib/y_support/typing/module/typing.rb
y_support-2.0.29 lib/y_support/typing/module/typing.rb
y_support-2.0.28 lib/y_support/typing/module/typing.rb