hash method in ruby
I did not know about hash method in ruby object and I paid a heavy price. While developing admin_data plugin I proposed to pass certain values in configuration like this.
:column_settings => { Car => { :data => lambda{|model| model.send(:data).inspect}}}
With the above settings the code will work fine the very first time in development mode. However if you refresh the page then code was failing. It turns out that when I ask ruby to use a class as a hash key then ruby calls hash method of the class and that output is stored as a key.
Since rails loads new instances of classes in development every single time, the hash value of the class differs each time. Check this out.
>> User.hash => 18513330 >> reload! Reloading... => true >> User.hash => 18403950
The fix would be to use symbol (like :user) or string (like ‘User’) as key of a hash.


Recent comments
1 year 23 weeks ago
1 year 23 weeks ago
1 year 25 weeks ago
1 year 27 weeks ago
1 year 42 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 46 weeks ago
1 year 48 weeks ago