Class: Steep::Interface::Interface::Combination
- Inherits:
-
Object
- Object
- Steep::Interface::Interface::Combination
- Defined in:
- lib/steep/interface/interface.rb
Instance Attribute Summary collapse
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Class Method Summary collapse
Instance Method Summary collapse
- #incompatible!(value) ⇒ Object
- #incompatible? ⇒ Boolean
-
#initialize(operator:, types:) ⇒ Combination
constructor
A new instance of Combination.
- #intersection? ⇒ Boolean
- #overload? ⇒ Boolean
- #to_s ⇒ Object
- #union? ⇒ Boolean
Constructor Details
#initialize(operator:, types:) ⇒ Combination
Returns a new instance of Combination.
8 9 10 11 12 |
# File 'lib/steep/interface/interface.rb', line 8 def initialize(operator:, types:) @types = types @operator = operator @incompatible = false end |
Instance Attribute Details
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
5 6 7 |
# File 'lib/steep/interface/interface.rb', line 5 def operator @operator end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
6 7 8 |
# File 'lib/steep/interface/interface.rb', line 6 def types @types end |
Class Method Details
.intersection(types) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/steep/interface/interface.rb', line 50 def self.intersection(types) case types.size when 0 raise "Combination.intersection called with zero types" when 1 types.first else new(operator: :intersection, types: types) end end |
.overload(types, incompatible:) ⇒ Object
26 27 28 |
# File 'lib/steep/interface/interface.rb', line 26 def self.overload(types, incompatible:) new(operator: :overload, types: types).incompatible!(incompatible) end |
.union(types) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/steep/interface/interface.rb', line 39 def self.union(types) case types.size when 0 raise "Combination.union called with zero types" when 1 types.first else new(operator: :union, types: types) end end |
Instance Method Details
#incompatible!(value) ⇒ Object
34 35 36 37 |
# File 'lib/steep/interface/interface.rb', line 34 def incompatible!(value) @incompatible = value self end |
#incompatible? ⇒ Boolean
30 31 32 |
# File 'lib/steep/interface/interface.rb', line 30 def incompatible? @incompatible end |
#intersection? ⇒ Boolean
22 23 24 |
# File 'lib/steep/interface/interface.rb', line 22 def intersection? operator == :intersection end |
#overload? ⇒ Boolean
14 15 16 |
# File 'lib/steep/interface/interface.rb', line 14 def overload? operator == :overload end |
#to_s ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/steep/interface/interface.rb', line 61 def to_s case operator when :overload "{ #{types.map(&:to_s).join(" | ")} }" when :union "[#{types.map(&:to_s).join(" | ")}]" when :intersection "[#{types.map(&:to_s).join(" & ")}]" end end |
#union? ⇒ Boolean
18 19 20 |
# File 'lib/steep/interface/interface.rb', line 18 def union? operator == :union end |