Mega Code Archive
Search
.Net
ASP .Net
ASP .Net Tutorial
C#
C# Book
C# by API
C# Tutorial
VB.Net
VB.Net by API
VB.Net Tutorial
Visual C++ .Net
VisualBasic Script
Java
Java
Java Book
Java by API
Java Tutorial
Script
Flash ActionScript
Flex
JavaScript DHTML
JavaScript Reference
JavaScript Tutorial
Database
MSSQL
MSSQL Tutorial
MySQL
MySQL Tutorial
Oracle PLSQL
Oracle PLSQL Tutorial
PostgreSQL
Languages
Android
C
C Tutorial
C++
C++ Tutorial
Delphi
Perl
PHP
Python
Python Tutorial
Ruby
Silverlight
Office
MSOfficeExcel 2007 Tutorial
MSOfficePowerPoint 2007 Tutorial
MSOfficeWord 2007 Tutorial
Data
XML
XML Tutorial
Ruby
Hash 112 codes
Home
Ruby
Hash
1 A hash ( associative array or a dictionary) is an array holding a collection of data
2 Access any key in a hash that has a default value
3 Access array embedded within a hash
4 Accessing Hashes
5 Add method hash class to invert a hash
6 Add method to Hash class to remove one hash from another
7 Adds the value Six with a key 6 Or you can use []= to change a value
8 Assign key and value pair to a string in hash each method
9 Associate an array converted from a hash
10 Change values in hash in the same way as an array
11 Changes the value associated with the key 2 to Bent
12 Changing Hashes
13 Checking for the presence of keys in a hash
14 Clear a hash
15 Clear method removes all the key-value pairs from a hash, leaving it empty
16 Convert hash to a hash and check the object id
17 Convert hash to array
18 Convert hash to string
19 Create a hash with default value
20 Creates a new default object each time
21 Creating a Hash with a Default Value
22 Creating Hashes
23 Default(key=nil ) Returns the default value
24 Default= Sets the default value
25 Delete element from hash
26 Delete from hash
27 Delete if for a certain value
28 Delete if with block logics
29 Delete_if passes all pairs into the block, so you can delete based on a key or a value
30 Delete_if uses a block
31 Deleting and Clearing a Hash
32 Deleting Hash Elements
33 Deleting Hash Elements Conditionally
34 Each_key method passes only the keys to the block
35 Element Assignment
36 Equality
37 Extract data from the hash by using its keys
38 Find a key-value pair
39 Find all
40 Frozen is kept in variable assignment but not converting
41 Get all keys from a hash
42 Get all values as an array
43 Get an array with all the values from a hash with values
44 Get Hash value by index
45 Grep a hash
46 Hash as a key
47 Hash has a class method [], which is called in either one of two ways
48 Hash inject
49 Hash new with block logic
50 Hash with =
51 Hashes use braces instead of brackets to let the Ruby interpreter know what is being created
52 Hashes Within Hashes
53 If the key is not defined, return the successor of the key
54 Inject with regular expression
55 Instead of integers, you could use strings for the keys
56 Is a hash empty
57 Is it a value in the hash
58 Iterating Through Hash Elements
59 Join hash keys together
60 Loop hash with interpolation
61 Loop through all keys
62 Loop through all values
63 Merge method merges two hashes together, producing a copy of the hashes that removes duplicate keys by overwriting the key-value pair
64 Merge two hashes
65 Merge two hashes with block logics
66 Objects within a hash are given a key that points to them
67 Output hash to string then remove the key and gsub
68 Pass a block to your call to delete
69 Print a hash with PP module
70 Print out a nested hash
71 Printing a Hash
72 Pulling stuff out of zip
73 Rehash Rebuilds the hash based on the current hash values for each key
74 Reject and delete from hash with block
75 Replace a hash with another key-value pair
76 Replace all of the pairs in h with those from another hash
77 Replace hash with a constant
78 Retrieve the values out of a hash based on one or more keys with values_at, also placing the value or values in an array
79 Retrieving Keys
80 Return a value for a given key (one key only) with the index method
81 Return an array containing all the keys in a hash with keys
82 RuntimeError
83 Searching a Hash with Regular Expressions
84 See if it has a given value with value or has_value
85 Shift a hash
86 Sort a hash
87 Sort a hash with sort_by
88 Store new value a hash
89 Swap keys and values
90 Test how big it is with length or size
91 The each_value method passes all the values to a block
92 The hash definition is enclosed in curly braces, whereas an array is defined in square brackets
93 The variable storing the hash is dictionary, and it contains two entries
94 This lazily initialized hash maps integers to their factorials
95 Time value key
96 Update is a synonym for merge!
97 Use each to loop through a hash
98 Use new to create a hash with a default value which is otherwise just nil
99 Use number as hash key
100 Use select to get value by condition
101 Use square brackets to reference the element you wish to retrieve
102 Using Hashes
103 Using merge with a block
104 Using puts on a hash in Ruby doesnt result in as nice a display as it does for arrays
105 Values Returns an array populated with the values fromhsh
106 Values_at(key) Returns an array consisting of values for the given key(s)
107 What if a key does not exist
108 What is the default value for a hash
109 When you sort a hash with the sort method, you get a multidimensional array of two-element arrays in return
110 You can store numbers in hashes
111 You can test to see if a hash is empty with empty
112 You can use the length method on hashes just as you can on arrays