Class: MultiType::Group
- Inherits:
-
Object
- Object
- MultiType::Group
- Defined in:
- lib/multi_type/group.rb
Instance Attribute Summary collapse
-
#klasses ⇒ Object
(also: #to_a)
readonly
Returns the value of attribute klasses.
Instance Method Summary collapse
- #===(other) ⇒ Object
-
#initialize(klasses) ⇒ Group
constructor
A new instance of Group.
- #inspect ⇒ Object
- #to_module ⇒ Object
Constructor Details
#initialize(klasses) ⇒ Group
Returns a new instance of Group.
6 7 8 |
# File 'lib/multi_type/group.rb', line 6 def initialize(klasses) @klasses = klasses.uniq end |
Instance Attribute Details
#klasses ⇒ Object (readonly) Also known as: to_a
Returns the value of attribute klasses.
3 4 5 |
# File 'lib/multi_type/group.rb', line 3 def klasses @klasses end |
Instance Method Details
#===(other) ⇒ Object
10 11 12 |
# File 'lib/multi_type/group.rb', line 10 def ===(other) klasses.any? { |k| k === other } end |
#inspect ⇒ Object
14 15 16 |
# File 'lib/multi_type/group.rb', line 14 def inspect ?< + klasses.map(&:inspect) * ", " + ?> end |
#to_module ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/multi_type/group.rb', line 18 def to_module group = self Module.new do extend self %i[inspect to_a ===].each do |m| define_method m do |*args| group.public_send m, *args end end def add(*other) MultiType[*self, *other] end end end |