D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
ObjectSpace
/
WeakKeyMap
/
Filename :
getkey-i.ri
back
Copy
U:RDoc::AnyMethod[iI"getkey:ETI"#ObjectSpace::WeakKeyMap#getkey;TF:publico:RDoc::Markup::Document:@parts[ o:RDoc::Markup::Paragraph; [I"JReturns the existing equal key if it exists, otherwise returns +nil+.;To:RDoc::Markup::BlankLine o; ; [I"LThis might be useful for implementing caches, so that only one copy of ;TI"9some object would be used everywhere in the program:;T@o:RDoc::Markup::Verbatim; [I"*value = {amount: 1, currency: 'USD'} ;TI" ;TI"-# Now if we put this object in a cache: ;TI")cache = ObjectSpace::WeakKeyMap.new ;TI"cache[value] = true ;TI" ;TI"D# ...we can always extract from there and use the same object: ;TI"7copy = cache.getkey({amount: 1, currency: 'USD'}) ;TI"/copy.object_id == value.object_id #=> true;T:@format0: @fileI"weakmap.c;T:0@omit_headings_from_table_of_contents_below0I",map.getkey(key) -> existing_key or nil ;T0[ I" (p1);T@FI"WeakKeyMap;TcRDoc::NormalClass00