Skip to content

Instantly share code, notes, and snippets.

@selvait90
Created July 27, 2015 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save selvait90/58cdf5c46fe89feeeea7 to your computer and use it in GitHub Desktop.
Save selvait90/58cdf5c46fe89feeeea7 to your computer and use it in GitHub Desktop.
Ordered Hash
>> oh=ActiveSupport::OrderedHash.new
=> #<OrderedHash {}>
>> oh
=> #<OrderedHash {}>
>> oh['secondary_entity_id']= "169435" => "169435"
>> oh["place_entity_attributes"] = {"id"=>"123456"}
=> {"id"=>"123456"}
>> oh
=> #<OrderedHash {"place_entity_attributes"=>{"id"=>"123456"}, "secondary_entity_id"=>"169435"}>
>> oh.sort.reverse
=> [["secondary_entity_id", "169435"], ["place_entity_attributes", {"id"=>"123456"}]]
?> Hash[oh.sort.reverse]
=> {"place_entity_attributes"=>{"id"=>"123456"}, "secondary_entity_id"=>"169435"}
>> OrderedHash[oh.sort.reverse]
NameError: uninitialized constant OrderedHash
from /home/selva/.rbenv/versions/ree-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-63daeef511db/activesupport/lib/active_support/dependencies.rb:469:in `load_missing_co
nstant'
from /home/selva/.rbenv/versions/ree-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-63daeef511db/activesupport/lib/active_support/dependencies.rb:106:in `const_missing'
from /home/selva/.rbenv/versions/ree-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-63daeef511db/activesupport/lib/active_support/dependencies.rb:118:in `const_missing'
from (irb):120
from :0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment