Class: JRuby::ScalaSupport::Map::Mutable
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Common
#[], #as_json, #each, #eql?, #has_key?, #key, #keys, #to_s, #value?, #values
Class Method Details
.[](*args) ⇒ Object
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/jruby/scala_support.rb', line 185
def [](*args)
hash = new
if args.size == 1
obj = args.first
case obj
when Array, Hash then obj.each {|k,v| hash[k] = v}
else
raise "Don't yet know what to do with a #{obj.inspect}"
end
return hash
end
return new if args.empty?
if args.size & 1 == 1
raise ArgumentError, "Expected an even number, got #{args.length}"
end
i = 0
total = args.size
while i < total
hash[args[i]] = args[i+1]
i += 2
end
hash
end
|
.new(default_value = nil, &default_block) ⇒ Object
214
215
216
217
218
219
220
221
222
|
# File 'lib/jruby/scala_support.rb', line 214
def new(default_value=nil, &default_block)
raise ArgumentError, "You can only provide either a default value or a block" if default_value && default_block
h = scala.collection.mutable.HashMap.new
if default_block
h = h.with_default {|k| default_block.call(h,k) }
end
h = h.with_default_value(default_value) if default_value
previous_new(h)
end
|
.previous_new ⇒ Object
183
|
# File 'lib/jruby/scala_support.rb', line 183
alias_method :previous_new, :new
|
Instance Method Details
#[]=(key, value) ⇒ Object
225
226
227
|
# File 'lib/jruby/scala_support.rb', line 225
def []=(key, value)
@raw.update(key, value.to_scala)
end
|