Class: MultiType::Group
- Inherits:
-
Object
- Object
- MultiType::Group
- Defined in:
- lib/multi_type/group.rb
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.
3 4 5 |
# File 'lib/multi_type/group.rb', line 3 def initialize(klasses) @klasses = klasses end |
Instance Method Details
#===(other) ⇒ Object
7 8 9 |
# File 'lib/multi_type/group.rb', line 7 def ===(other) @klasses.any? { |k| k === other } end |
#inspect ⇒ Object
11 12 13 |
# File 'lib/multi_type/group.rb', line 11 def inspect ?< + @klasses.map(&:inspect).join(", ") + ?> end |
#to_module ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/multi_type/group.rb', line 15 def to_module group = self Module.new do extend self i[inspect ===].each do |m| define_method m do |*args| group.public_send m, *args end end def add(*other) MultiType[self, *other] end end end |