Class: 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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*patterns) ⇒ Any

Returns a new instance of Any.



1360
1361
1362
# File 'lib/magic_xml.rb', line 1360

def initialize(*patterns)
  @patterns = patterns
end

Class Method Details

.[](*patterns) ⇒ Object



1366
1367
1368
# File 'lib/magic_xml.rb', line 1366

def self.[](*patterns)
  new(*patterns)
end

Instance Method Details

#===(obj) ⇒ Object



1363
1364
1365
# File 'lib/magic_xml.rb', line 1363

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