Class: OptionInitializer::ClassMatch
- Inherits:
-
Object
- Object
- OptionInitializer::ClassMatch
- Defined in:
- lib/option_initializer.rb
Instance Method Summary collapse
-
#initialize(*classes) ⇒ ClassMatch
constructor
A new instance of ClassMatch.
- #match(object) ⇒ Object
- #to_s ⇒ Object
- #|(other_class) ⇒ Object
Constructor Details
#initialize(*classes) ⇒ ClassMatch
Returns a new instance of ClassMatch.
70 71 72 |
# File 'lib/option_initializer.rb', line 70 def initialize *classes @classes = Set[*classes] end |
Instance Method Details
#match(object) ⇒ Object
81 82 83 |
# File 'lib/option_initializer.rb', line 81 def match object @classes.any? { |k| object.is_a? k } end |
#to_s ⇒ Object
85 86 87 88 |
# File 'lib/option_initializer.rb', line 85 def to_s a = @classes.map(&:to_s) [a[0...-1].join(', '), a.last].reject(&:empty?).join(', or ') end |
#|(other_class) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/option_initializer.rb', line 74 def | other_class unless other_class.is_a?(Class) raise TypeError, "wrong argument type (expected: Class)" end ClassMatch.new(*@classes.union([other_class])) end |