Class | Irc::NetmaskList |
In: |
lib/rbot/irc.rb
|
Parent: | ArrayOf |
A NetmaskList is an ArrayOf Netmasks
Create a new NetmaskList, optionally filling it with the elements from the Array argument fed to it.
# File lib/rbot/irc.rb, line 872 872: def initialize(ar=[]) 873: super(Netmask, ar) 874: end
We enhance the [] method by allowing it to pick an element that matches a given Netmask, a String or a Regexp TODO take into consideration the opportunity to use select() instead of find(), and/or a way to let the user choose which one to take (second argument?)
# File lib/rbot/irc.rb, line 882 882: def [](*args) 883: if args.length == 1 884: case args[0] 885: when Netmask 886: self.find { |mask| 887: mask.matches?(args[0]) 888: } 889: when String 890: self.find { |mask| 891: mask.matches?(args[0].to_irc_netmask(:casemap => mask.casemap)) 892: } 893: when Regexp 894: self.find { |mask| 895: mask.fullform =~ args[0] 896: } 897: else 898: super(*args) 899: end 900: else 901: super(*args) 902: end 903: end