Ruby hash yog dab tsi?
Ruby hash yog dab tsi?

Video: Ruby hash yog dab tsi?

Video: Ruby hash yog dab tsi?
Video: NKAIS THAB XUB By PajSuab Xyooj (Official MV) Nkauj Tawm Tshiab 2023. 2024, Kaum ib hlis
Anonim

Ruby Hashes . A Ruby hash yog ib phau ntawm cov yuam sij tshwj xeeb thiab lawv cov txiaj ntsig. Lawv zoo ib yam li arrays tab sis array siv tus lej ua qhov ntsuas thiab hash siv tej yam khoom. Lawv tseem hu ua associative arrays, dictionaries lossis maps. Yog ib hash yog nkag tau nrog tus yuam sij uas tsis muaj nyob, txoj kev yuav rov qab nil.

Ua raws li qhov xav tau, koj txhais li cas hash hauv Ruby?

Hauv Ruby koj tuaj yeem tsim ib qho Hash los ntawm muab tus yuam sij rau tus nqi nrog =>, cais cov yuam sij / tus nqi no nrog commas, thiab kaw tag nrho cov khoom nrog curly braces.

Ib yam li ntawd, koj yuav ua li cas tshem tus yuam sij los ntawm hash hauv Ruby? Muaj ntau txoj hauv kev los tshem tawm tus yuam sij los ntawm hash thiab tau txais cov hash ntxiv hauv Ruby.

  1. hlais => Nws yuav rov qab xaiv cov yuam sij thiab tsis rho tawm ntawm tus thawj hash.
  2. rho tawm => Nws yuav rho tawm cov yuam sij xaiv los ntawm tus thawj hash (nws tuaj yeem txais tsuas yog ib tus yuam sij thiab tsis ntau tshaj ib qho).

Ib tug kuj yuav nug, dab tsi yog lub cim Ruby?

A Cim yog qhov yooj yim tshaj plaws Ruby khoom koj tsim tau. Nws tsuas yog lub npe thiab tus ID sab hauv. Cov cim muaj txiaj ntsig vim muab cim lub npe hais txog tib yam khoom thoob plaws a Ruby qhov kev pab cuam. Ob txoj hlua nrog tib cov ntsiab lus yog ob yam khoom sib txawv, tab sis rau ib lub npe muaj tsuas yog ib qho Cim khoom.

Hash object yog dab tsi?

A hash khoom yog dynamically tsim nyob rau hauv lub cim xeeb ntawm run-time. Qhov loj ntawm a hash khoom loj hlob raws li cov khoom ntxiv thiab nws cog lus thaum cov khoom raug tshem tawm. A hash khoom muaj cov kab tseem ceeb, cov kab ntawv, thiab cov txheej txheem xws li DECLARE, FIND, thiab lwm yam A hash cov khoom Scope yog txwv rau cov kauj ruam DATA uas nws tau tsim.

Pom zoo: