Class: Patterns_any

Inherits:
Object
  • Object
show all
Defined in:
lib/magic_xml.rb

Overview

Perl 6 is supposed to have native support for something like that. Constructor takes multiple patterns. The object matches if they all match.

Usage:

case foo
when all(:foo, any({:color => 'blue'}, {:color => 'red'}), /Hello/)
     print foo
end

Instance Method Summary collapse

Constructor Details

#initialize(*patterns) ⇒ Patterns_any

Returns a new instance of Patterns_any.



1369
1370
1371
# File 'lib/magic_xml.rb', line 1369

def initialize(*patterns)
    @patterns = patterns
end

Instance Method Details

#===(obj) ⇒ Object



1372
1373
1374
# File 'lib/magic_xml.rb', line 1372

def ===(obj)
    @patterns.any?{|p| p === obj}
end