Skip to content

Commit

Permalink
Added a blurb on how the curly braces can be skipped on hashes if the…
Browse files Browse the repository at this point in the history
…y are a last param to a function
  • Loading branch information
gauthamchandra committed Apr 13, 2015
1 parent 2a8f09b commit def338c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion primitives_and_other_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ a = { status: 'zombie', name:'Katie', id: 5 }
a[:status] #Same as a['status']
```

####Alternate notation for key value seperators using ```=>```
####Alternate notation for key value seperators using the hashrocket: ```=>```

Instead of using ```:``` to seperate key value pairs, In Ruby, one can also use ```=>``` instead.

Expand All @@ -134,6 +134,17 @@ stuff = {
};
```

####Ommitting the ```{}```

When passing a hash to a function, if the hash is the last parameter, the ```{}``` can be ommitted.

So if there is a method ```foo``` that takes in 1 hash as a parameter:

```
foo({ 'status' => 'zombie' }) # This...
foo('status' => 'zombie') # is the same as this
```

###via Hash.new:

Hash.new takes in an optional parameter for the default value. If set, anytime a non-existent key is accessed or an operation is done on a key that has no value, this default value is returned instead.
Expand Down

0 comments on commit def338c

Please sign in to comment.