25 Oct '13, 10pm

really useful ActiveSupport HashWithIndifferentAccess

Implements a hash where keys :foo and "foo" are considered to be the same. rgb = ActiveSupport :: HashWithIndifferentAccess .new rgb [:black ] = '#000000' rgb [:black ] # => '#000000' rgb ['black' ] # => '#000000' rgb ['white' ] = '#FFFFFF' rgb [:white ] # => '#FFFFFF' rgb ['white' ] # => '#FFFFFF' Internally symbols are mapped to strings when used as keys in the entire writing interface (calling []= , merge , etc). This mapping belongs to the public interface. For example, given: hash = ActiveSupport::HashWithIndifferentAccess.new(a: 1) You are guaranteed that the key is returned as a string: hash .keys # => ["a"] Technically other types of keys are accepted: hash = ActiveSupport :: HashWithIndifferentAccess .new (a : 1 ) hash [0 ] = 0 hash # => {"a"=>1, 0=>0} but this class is intended for use cases where strings or symbols are the expected keys and it is convenient to u...

Full article: http://api.rubyonrails.org/classes/ActiveSupport/HashWith...

Tweets

Cool Websites & Tools – Bitcoin Digital Wallet, Clip Useful Phrases, & Lookup Phone Numbers

Cool Websites & Tools – Bitcoin Digital Wallet,...

makeuseof.com 25 Oct '13, 10pm

By Mark O'Neill on 25th October, 2013 | The Internet | No Comments Emu Messenger – is a messaging app for Android with a b...

What's in a name, really ? | @LoyarBurok #Malay...

loyarburok.com 23 Oct '13, 4pm

Will the Parliament someday pass a Malaysianised Name Act? With politicians adopting a divide and rule approach, I do not ...