@element_class = kl\r
case ar\r
when Array\r
- send(:+, ar)\r
+ insert(0, *ar)\r
else\r
raise TypeError, "#{self.class} can only be initialized from an Array"\r
end\r
end\r
\r
+ def inspect\r
+ "#<#{self.class}[#{@element_class}]:#{'0x%x' % self.object_id}: #{super}>"\r
+ end\r
+\r
# Private method to check the validity of the elements passed to it\r
# and optionally raise an error\r
#\r
super(el) if internal_will_accept?(true, el)\r
end\r
\r
+ # Overloaded from Array#&, checks for appropriate class of argument elements\r
+ #\r
+ def &(ar)\r
+ r = super(ar)\r
+ ArrayOf.new(@element_class, r) if internal_will_accept?(true, *r)\r
+ end\r
+\r
+ # Overloaded from Array#+, checks for appropriate class of argument elements\r
+ #\r
+ def +(ar)\r
+ ArrayOf.new(@element_class, super(ar)) if internal_will_accept?(true, *ar)\r
+ end\r
+\r
+ # Overloaded from Array#-, so that an ArrayOf is returned. There is no need\r
+ # to check the validity of the elements in the argument\r
+ #\r
+ def -(ar)\r
+ ArrayOf.new(@element_class, super(ar)) # if internal_will_accept?(true, *ar)\r
+ end\r
+\r
+ # Overloaded from Array#|, checks for appropriate class of argument elements\r
+ #\r
+ def |(ar)\r
+ ArrayOf.new(@element_class, super(ar)) if internal_will_accept?(true, *ar)\r
+ end\r
+\r
+ # Overloaded from Array#concat, checks for appropriate class of argument\r
+ # elements\r
+ #\r
+ def concat(ar)\r
+ super(ar) if internal_will_accept?(true, *ar)\r
+ end\r
+\r
+ # Overloaded from Array#insert, checks for appropriate class of argument\r
+ # elements\r
+ #\r
+ def insert(idx, *ar)\r
+ super(idx, *ar) if internal_will_accept?(true, *ar)\r
+ end\r
+\r
+ # Overloaded from Array#replace, checks for appropriate class of argument\r
+ # elements\r
+ #\r
+ def replace(ar)\r
+ super(ar) if (ar.kind_of?(ArrayOf) && ar.element_class <= @element_class) or internal_will_accept?(true, *ar)\r
+ end\r
+\r
+ # Overloaded from Array#push, checks for appropriate class of argument\r
+ # elements\r
+ #\r
+ def push(*ar)\r
+ super(*ar) if internal_will_accept?(true, *ar)\r
+ end\r
+\r
# Overloaded from Array#unshift, checks for appropriate class of argument(s)\r
#\r
def unshift(*els)\r
}\r
end\r
\r
- # Overloaded from Array#+, checks for appropriate class of argument elements\r
+ # Modifying methods which we don't handle yet are made private\r
#\r
- def +(ar)\r
- super(ar) if internal_will_accept?(true, *ar)\r
- end\r
+ private :[]=, :collect!, :map!, :fill, :flatten!\r
+\r
end\r
\r
\r
end\r
\r
def inspect\r
- str = "<#{self.class}:#{'0x%08x' % self.object_id}:"\r
+ str = "<#{self.class}:#{'0x%x' % self.object_id}:"\r
str << " @nick=#{@nick.inspect} @user=#{@user.inspect}"\r
- str << " @host=<#{@host}>"\r
+ str << " @host=#{@host.inspect}>"\r
str\r
end\r
\r
attr_reader :name, :topic, :mode, :users, :server\r
alias :to_s :name\r
\r
- # A String describing the Channel and (some of its) internals\r
- #\r
def inspect\r
- str = "<#{self.class}:#{'0x%08x' % self.object_id}:"\r
+ str = "<#{self.class}:#{'0x%x' % self.object_id}:"\r
str << " on server #{server}"\r
str << " @name=#{@name.inspect} @topic=#{@topic.text.inspect}"\r
str << " @users=<#{@users.sort.join(', ')}>"\r
u.inspect\r
}.sort\r
\r
- str = "<#{self.class}:#{'0x%08x' % self.object_id}:"\r
+ str = "<#{self.class}:#{'0x%x' % self.object_id}:"\r
str << " @channels=#{chans}"\r
str << " @users=#{users}>"\r
str\r
end\r
\r
end\r
+\r
end\r
\r