Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails5 - ruby 2.2.3 // how ActiveSupport::TimeZone changed?

Asking a question yesterday (here) about time zones, the following is not working with rails 5 running on ruby 2.2.3 :

ActiveSupport::TimeZone.zones_map

Where can one read about the differences of use between with this new version ? What could be the way to achieve the same ?

like image 395
Ben Avatar asked Apr 14 '26 10:04

Ben


1 Answers

The best way is to look into the current source code for the TimeZone in ActiveSupport: the zones_map method has been made private, so I guess you are getting this error under Rails 5:

NoMethodError: private method 'zones_map' called for ActiveSupport::TimeZone:Class

So now you have two options: either use send to call the private method anyway:

ActiveSupport::TimeZone.send(:zones_map)

Or, even better, if all you need is values of this map (as suggested in the answer to your yesterday's question), then there is no need to hack around the zones_map. You can use the all method instead:

ActiveSupport::TimeZone.all

According to the source, the all method is equivalent to zones_map.values.sort and it is a normal public method so there's no need to send anything.

like image 180
Matouš Borák Avatar answered Apr 16 '26 01:04

Matouš Borák



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!