10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/jactive_support/java_ext/map/constructor.rb', line 10
def [](*args)
r = self.new
if args.size == 1 && ( args.first.respond_to?(:to_ary) || args.first.respond_to?(:to_hash) )
args = args.first
if args.respond_to?(:to_ary)
args = args.to_ary
elsif args.respond_to?(:to_hash)
args = args.to_hash
end
args.each do |e|
next unless e.respond_to? :to_ary
e = e.to_ary
r.put(e.shift, e.shift) if (1..2).include?(e.size)
end
else
raise ArgumentError, "odd number of arguments for constructor" unless (args.size % 2) == 0
args.each_slice(2) {|key,val| r.put(key,val)}
end
r
end
|