Class: WebFunction::Type::Union
- Inherits:
-
Object
- Object
- WebFunction::Type::Union
- Defined in:
- lib/web_function/type/union.rb
Instance Attribute Summary collapse
-
#members ⇒ Object
readonly
Returns the value of attribute members.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #base_type ⇒ Object
- #format(format = :default) ⇒ Object
- #hash ⇒ Object
-
#initialize(members) ⇒ Union
constructor
A new instance of Union.
- #inspect ⇒ Object
- #objects ⇒ Object
- #refinement ⇒ Object
- #to_s ⇒ Object
- #valid?(value) ⇒ Boolean
- #without_refinements ⇒ Object
Constructor Details
#initialize(members) ⇒ Union
Returns a new instance of Union.
8 9 10 |
# File 'lib/web_function/type/union.rb', line 8 def initialize(members) @members = members end |
Instance Attribute Details
#members ⇒ Object (readonly)
Returns the value of attribute members.
6 7 8 |
# File 'lib/web_function/type/union.rb', line 6 def members @members end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
32 33 34 |
# File 'lib/web_function/type/union.rb', line 32 def ==(other) other.is_a?(Union) && other.members == @members end |
#base_type ⇒ Object
12 13 14 |
# File 'lib/web_function/type/union.rb', line 12 def base_type nil end |
#format(format = :default) ⇒ Object
24 25 26 |
# File 'lib/web_function/type/union.rb', line 24 def format(format = :default) @members.map { |member| member.format(format) }.join(" | ") end |
#hash ⇒ Object
37 38 39 |
# File 'lib/web_function/type/union.rb', line 37 def hash [Union, @members].hash end |
#inspect ⇒ Object
20 21 22 |
# File 'lib/web_function/type/union.rb', line 20 def inspect "#<Union #{@members.map(&:inspect).join(" | ")}>" end |
#objects ⇒ Object
41 42 43 |
# File 'lib/web_function/type/union.rb', line 41 def objects @members.flat_map(&:objects).uniq end |
#refinement ⇒ Object
16 17 18 |
# File 'lib/web_function/type/union.rb', line 16 def refinement nil end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/web_function/type/union.rb', line 28 def to_s format(:default) end |
#valid?(value) ⇒ Boolean
49 50 51 |
# File 'lib/web_function/type/union.rb', line 49 def valid?(value) @members.any? { |member| member.valid?(value) } end |