### Home Classes Methods

### In Files

- lib/rbot/irc.rb

### Parent

Array

### Methods

- ::new
- #&
- #+
- #-
- #<<
- #concat
- #downcase
- #insert
- #inspect
- #internal_will_accept?
- #push
- #replace
- #unshift
- #valid?
- #validate
- #will_accept?
- #|

### Class/Module Index

Quicksearch

- Irc
- Irc::AsciiCasemap
- Irc::BanlistMessage
- Irc::BasicUserMessage
- Irc::Bot
- Irc::Bot::Auth
- Irc::Bot::Auth::BotOwnerClass
- Irc::Bot::Auth::BotUser
- Irc::Bot::Auth::Command
- Irc::Bot::Auth::DefaultBotUserClass
- Irc::Bot::Auth::InvalidPassword
- Irc::Bot::Auth::ManagerClass
- Irc::Bot::Auth::PermissionSet
- Irc::Bot::Config
- Irc::Bot::Config::ArrayValue
- Irc::Bot::Config::BooleanValue
- Irc::Bot::Config::EnumValue
- Irc::Bot::Config::FloatValue
- Irc::Bot::Config::IntegerValue
- Irc::Bot::Config::ManagerClass
- Irc::Bot::Config::StringValue
- Irc::Bot::Config::Value
- Irc::Bot::Config::Wizard
- Irc::Bot::DataFilter
- Irc::Bot::DataStream
- Irc::Bot::Language
- Irc::Bot::MessageMapper
- Irc::Bot::MessageMapper::Failure
- Irc::Bot::MessageMapper::FriendlyFailure
- Irc::Bot::MessageMapper::NoActionFailure
- Irc::Bot::MessageMapper::NoMatchFailure
- Irc::Bot::MessageMapper::NotPrivateFailure
- Irc::Bot::MessageMapper::NotPublicFailure
- Irc::Bot::MessageMapper::PartialMatchFailure
- Irc::Bot::MessageParameter
- Irc::Bot::MessageTemplate
- Irc::Bot::Plugins
- Irc::Bot::Plugins::BotModule
- Irc::Bot::Plugins::CoreBotModule
- Irc::Bot::Plugins::Plugin
- Irc::Bot::Plugins::PluginManagerClass
- Irc::Bot::Plugins::RecurseTooDeep
- Irc::Bot::Plugins::RemoteBotModule
- Irc::Bot::Plugins::RemoteCoreBotModule
- Irc::Bot::Plugins::RemotePlugin
- Irc::Bot::Registry
- Irc::Bot::Registry::Accessor
- Irc::Bot::RemoteDispatcher
- Irc::Bot::RemoteMessage
- Irc::Bot::RemoteObject
- Irc::Bot::Wordlist
- Irc::BotConfig
- Irc::Casemap
- Irc::Channel
- Irc::Channel::Mode
- Irc::Channel::ModeHash
- Irc::Channel::ModeTypeA
- Irc::Channel::ModeTypeB
- Irc::Channel::ModeTypeC
- Irc::Channel::ModeTypeD
- Irc::Channel::Topic
- Irc::Channel::UserMode
- Irc::ChannelList
- Irc::Client
- Irc::DBHash
- Irc::DBTree
- Irc::InviteMessage
- Irc::JoinMessage
- Irc::KickMessage
- Irc::MessageQueue
- Irc::ModeChangeMessage
- Irc::MotdMessage
- Irc::NamesMessage
- Irc::Netmask
- Irc::NetmaskDb
- Irc::NetmaskDb::Tree
- Irc::NetmaskList
- Irc::NickMessage
- Irc::NoSuchTargetMessage
- Irc::NoticeMessage
- Irc::PartMessage
- Irc::PrivMessage
- Irc::QueueRing
- Irc::QuitMessage
- Irc::RfcCasemap
- Irc::Server
- Irc::ServerOrCasemap
- Irc::Socket
- Irc::Socket::IdentityFilter
- Irc::StrictRfcCasemap
- Irc::TopicMessage
- Irc::UnknownMessage
- Irc::User
- Irc::UserList
- Irc::UserMessage
- Irc::Utils
- Irc::Utils::HttpUtil
- Irc::Utils::HttpUtil::CachedObject
- Irc::Utils::ParseTime
- Irc::WelcomeMessage
- Irc::WhoisMessage
- BDB
- BDB::CIBtree
- MonitorMixin
- MonitorMixin::ConditionVariable
- Net
- Net::HTTPResponse
- Regexp
- Regexp::Irc
- Singleton
- Singleton::SingletonClassMethods
- Timer
- Timer::Action
- TokyoCabinet
- TokyoCabinet::CIBDB
- UnicodePlugin
- UnicodePlugin::UnicodeFilter
- Array
- ArrayOf
- AuthModule
- BasicsModule
- ConditionVariable
- ConfigModule
- DottedIndex
- Enumerable
- Exception
- FiltersModule
- GetText
- GetTextVersionError
- HttpUtilPlugin
- IrcLogModule
- Module
- Numeric
- Object
- Range
- RemoteModule
- ServerError
- String
- Symbol
- UserDataModule
- WordlistModule
- YAML

No matching classes.

# ArrayOf

ArrayOf is a subclass of Array whose elements are supposed to be all of the same class. This is not intended to be used directly, but rather to be subclassed as needed (see for example Irc::UserList and Irc::NetmaskList)

Presently, only very few selected methods from Array are overloaded to check if the new elements are the correct class. An orthodox? method is provided to check the entire ArrayOf against the appropriate class.

### Attributes

element_class[R]

### Public Class Methods

new(kl, ar=[]) click to toggle source

Create a new ArrayOf whose elements are supposed to be all of type kl, optionally filling it with the elements from the Array argument.

    # File lib/rbot/irc.rb, line 374
    def initialize(kl, ar=[])
      raise TypeError, "#{kl.inspect} must be a class name" unless kl.kind_of?(Class)
      super()
      @element_class = kl
      case ar
      when Array
        insert(0, *ar)
      else
        raise TypeError, "#{self.class} can only be initialized from an Array"
      end
    end

### Public Instance Methods

&(ar) click to toggle source

Overloaded from Array#&, checks for appropriate class of argument elements

    # File lib/rbot/irc.rb, line 433
    def &(ar)
      r = super(ar)
      ArrayOf.new(@element_class, r) if internal_will_accept?(true, *r)
    end

+(ar) click to toggle source

Overloaded from Array#+, checks for appropriate class of argument elements

    # File lib/rbot/irc.rb, line 440
    def +(ar)
      ArrayOf.new(@element_class, super(ar)) if internal_will_accept?(true, *ar)
    end

-(ar) click to toggle source

Overloaded from Array#-, so that an ArrayOf is returned. There is no need to check the validity of the elements in the argument

    # File lib/rbot/irc.rb, line 447
    def -(ar)
      ArrayOf.new(@element_class, super(ar)) # if internal_will_accept?(true, *ar)
    end

<<(el) click to toggle source

Overloaded from Array#<<, checks for appropriate class of argument

    # File lib/rbot/irc.rb, line 427
    def <<(el)
      super(el) if internal_will_accept?(true, el)
    end

concat(ar) click to toggle source

Overloaded from Array#concat, checks for appropriate class of argument elements

    # File lib/rbot/irc.rb, line 460
    def concat(ar)
      super(ar) if internal_will_accept?(true, *ar)
    end

downcase() click to toggle source

We introduce the 'downcase' method, which maps downcase() to all the Array elements, properly failing when the elements don't have a downcase method

    # File lib/rbot/irc.rb, line 496
    def downcase
      self.map { |el| el.downcase }
    end

insert(idx, *ar) click to toggle source

Overloaded from Array#insert, checks for appropriate class of argument elements

    # File lib/rbot/irc.rb, line 467
    def insert(idx, *ar)
      super(idx, *ar) if internal_will_accept?(true, *ar)
    end

inspect() click to toggle source

    # File lib/rbot/irc.rb, line 386
    def inspect
      self.__to_s__[0..-2].sub(/:[^:]+$/,"[#{@element_class}]\\0") + " #{super}>"
    end

push(*ar) click to toggle source

Overloaded from Array#push, checks for appropriate class of argument elements

    # File lib/rbot/irc.rb, line 481
    def push(*ar)
      super(*ar) if internal_will_accept?(true, *ar)
    end

replace(ar) click to toggle source

Overloaded from Array#replace, checks for appropriate class of argument elements

    # File lib/rbot/irc.rb, line 474
    def replace(ar)
      super(ar) if (ar.kind_of?(ArrayOf) && ar.element_class <= @element_class) or internal_will_accept?(true, *ar)
    end

unshift(*els) click to toggle source

Overloaded from Array#unshift, checks for appropriate class of argument(s)

    # File lib/rbot/irc.rb, line 487
    def unshift(*els)
      els.each { |el|
        super(el) if internal_will_accept?(true, *els)
      }
    end

valid?() click to toggle source

This method checks that all elements are of the appropriate class

    # File lib/rbot/irc.rb, line 414
    def valid?
      will_accept?(*self)
    end

validate() click to toggle source

This method is similar to the above, except that it raises an exception if the receiver is not valid

    # File lib/rbot/irc.rb, line 421
    def validate
      raise TypeError unless valid?
    end

will_accept?(*els) click to toggle source

This method checks if the passed arguments are acceptable for our ArrayOf

    # File lib/rbot/irc.rb, line 408
    def will_accept?(*els)
      internal_will_accept?(false, *els)
    end

|(ar) click to toggle source

Overloaded from Array#|, checks for appropriate class of argument elements

    # File lib/rbot/irc.rb, line 453
    def |(ar)
      ArrayOf.new(@element_class, super(ar)) if internal_will_accept?(true, *ar)
    end

### Private Instance Methods

internal_will_accept?(raising, *els) click to toggle source

Private method to check the validity of the elements passed to it and optionally raise an error

TODO should it accept nils as valid?

    # File lib/rbot/irc.rb, line 395
    def internal_will_accept?(raising, *els)
      els.each { |el|
        unless el.kind_of?(@element_class)
          raise TypeError, "#{el.inspect} is not of class #{@element_class}" if raising
          return false
        end
      }
      return true
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.