File: environment/context/type/signature/set-of-class.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: Environment#8
  module: Context#10
  module: Type#12
  module: Signature#14
has properties
function: make_set / 1 #70
constant: EMPTY_SET #76
  class: SetOfClass#16
inherits from
  Collection ( Umu::Abstraction )
has properties
attribute: hash [R] #17
method: initialize / 1 #20
method: empty? #34
method: member? / 1 #39
method: each #46
method: union / 1 #53

Code

   1  # coding: utf-8
   2  # frozen_string_literal: true
   3 
   4 
   5 
   6  module Umu
   7 
   8  module Environment
   9 
  10  module Context
  11 
  12  module Type
  13 
  14  module Signature
  15 
  16  class SetOfClass < Abstraction::Collection
  17      attr_reader :hash
  18 
  19 
  20      def initialize(signats)
  21          ASSERT.kind_of signats, ::Array
  22 
  23          @hash = signats.inject({}) { |hash, signat|
  24              ASSERT.kind_of signat, ECTSC::Base
  25 
  26              hash.merge(signat => true) {
  27                  ASSERT.abort(
  28                      "Duplicated a class signature: %s", signat.inspect
  29                  )
  30              }
  31          }.freeze
  32      end
  33 
  34      def empty?
  35          self.hash.empty?
  36      end
  37 
  38 
  39      def member?(signat)
  40          ASSERT.kind_of signat, ECTSC::Abstract
  41 
  42          self.hash.has_key? signat
  43      end
  44 
  45 
  46      def each
  47          self.hash.each_key do |signat|
  48              yield signat
  49          end
  50      end
  51 
  52 
  53      def union(other)
  54          ASSERT.kind_of other, SetOfClass
  55 
  56          SetOfClass.new(
  57              self.hash.merge(other.hash) { |signat, _, _|
  58                  ASSERT.abort(
  59                      "Duplicated a class signature: %s", signat.inspect
  60                  )
  61              }.keys.freeze
  62          ).freeze
  63      end
  64  end
  65 
  66 
  67 
  68  module_function
  69 
  70      def make_set(signats)
  71          ASSERT.kind_of signats, ::Array
  72 
  73          SetOfClass.new(signats.freeze).freeze
  74      end
  75 
  76  EMPTY_SET = make_set([])
  77 
  78  end # Umu::Environment::Context::Type::Signature
  79 
  80  end # Umu::Environment::Context::Type
  81 
  82  end # Umu::Environment::Context
  83 
  84  end # Umu::Environment
  85 
  86  end # Umu