This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| STATUS_MESSAGE_TYPES = Hash.new {|h,k| | |
| key = h.keys.find {|e| e.class == Range && e.include?(k) } | |
| key ? h[k] = h[key] : :undefined | |
| }.merge({ | |
| 100..102 => :informational, | |
| 200..208 => :success, | |
| 226 => :success, | |
| 300..308 => :redirection, | |
| 400..417 => :client_error, | |
| 422..431 => :client_error, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| some_hash = { :some_key => 'a value' } # standard syntax | |
| other_hash = { some_key: 'a value' } # Ruby 1.9 syntax |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| empty_hash = {} # using the hash literal syntax | |
| empty_hash = Hash.new # using the Hash class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| counter = Hash.new(0) # => {} | |
| counter[:monkey] += 1 # => 1 | |
| counter[:monkey] += 2 # => 3 | |
| counter # => {:monkey => 3} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| counter = {} # => {} | |
| counter[:monkey] += 1 # BOOM! NoMethodError: undefined method `+' for nil:NilClass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| STATUS_MESSAGES = { | |
| 200 => :ok, | |
| 201 => :created, | |
| 202 => :accepted | |
| } | |
| STATUS_MESSAGES[200] # => :ok | |
| STATUS_MESSAGES[999] # => nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| STATUS_MESSAGES = Hash.new(:undefined).merge({ | |
| 200 => :ok, | |
| 201 => :created, | |
| 202 => :accepted | |
| } | |
| STATUS_MESSAGES[200] # => :ok | |
| STATUS_MESSAGES[999] # => :undefined |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| STATUS_TYPES = { | |
| 200..208 => :success, | |
| 500..511 => :server_error | |
| } | |
| STATUS_TYPES[200] # => nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| STATUS_TYPES = Hash.new {|this_hash,missing_key| | |
| found_key = this_hash.keys.find {|this_key| this_key.class == Range && this_key.include?(missing_key) } | |
| found_key ? this_hash[missing_key] = this_hash[found_key] : :undefined | |
| }.merge({ | |
| 200..208 => :success, | |
| 500..511 => :server_error | |
| }) | |
| STATUS_TYPES.keys # => [200..208, 500..511] | |
| STATUS_TYPES[200] # => :success |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # settings {{{ | |
| config defaultToCurrentScreen true | |
| config nudgePercentOf screenSize | |
| config resizePercentOf screenSize | |
| alias gridSize 8,8 | |
| alias c (screenSizeX/8) | |
| alias r (screenSizeY/8) | |
| #}}} |
OlderNewer