Information Technology Reference
In-Depth Information
player. The value was another hash whose key is the name of the statistic and whose value is
the number of that statistic. This is better illustrated by the following sample data:
players = {
'McCutchen, Andrew' => {
'AVG' => 0 . 311 ,
'OBP' => 0 . 385 ,
'SLG' => 0 . 507
},
'Alvarez, Pedro' => {
'AVG' => 0 . 236 ,
'OBP' => 0 . 297 ,
'SLG' => 0 . 477
}
}
An individual player is accessed using his name as the key in the players hash. Because
players is a hash of hashes, the returned value is also a hash:
players [ 'McCutchen, Andrew' ] #=> { 'AVG' => 0.311, 'OBP' => 0.385, 'SLG' => 0.507 }
A particular statistic is accessible by nested bracket notation where the first key is the name
of the player and the second key is the name of the statistic:
players [ 'McCutchen, Andrew' ][ 'AVG' ] #=> 0.311
Regular Expressions
Ruby supports Perl-style regular expressions using the =~ operator:
"Bacon is good" =~ /lie/ #=> nil
"Bacon is good" =~ /bacon/ #=> 0
"Bacon is good" !~ /lie/
#=> true
Search WWH ::




Custom Search