Sha256: cc4dfb45edf2321e33e597169cbdcee1af7143f8d0d52fadd5f620882ca67590

Contents?: true

Size: 1.09 KB

Versions: 11

Compression:

Stored size: 1.09 KB

Contents

class Module
  # === Support for typing by declaration

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

  # Declared compliance 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

  # Using this method, the receiver explicitly declares that its interface
  # complies with another module (class).
  # 
  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

11 entries across 11 versions & 1 rubygems

Version Path
y_support-2.5.3 lib/y_support/typing/module/typing.rb
y_support-2.5.2 lib/y_support/typing/module/typing.rb
y_support-2.5.1 lib/y_support/typing/module/typing.rb
y_support-2.4.6 lib/y_support/typing/module/typing.rb
y_support-2.4.5 lib/y_support/typing/module/typing.rb
y_support-2.4.4 lib/y_support/typing/module/typing.rb
y_support-2.1.18 lib/y_support/typing/module/typing.rb
y_support-2.1.17 lib/y_support/typing/module/typing.rb
y_support-2.1.16 lib/y_support/typing/module/typing.rb
y_support-2.1.13 lib/y_support/typing/module/typing.rb
y_support-2.1.12 lib/y_support/typing/module/typing.rb