We have an app that uses the Sequel gem to connect to a data source, perform some work, and then return a result which has a number of convenience methods attached to the singleton_class
of that object. In ruby 2.3, this code is working as expected:
result = EpulseDB::Employee.where(normalized_args)
result.singleton_class.include(EpulseNormalization)
And we can see using ruby 2.3.4 the singleton_class is not frozen:
[1] pry(main)> result = EpulseDB::Employee.where(employee_id: 2)
=> #<Sequel::Postgres::Dataset: "SELECT * FROM \"employee\" WHERE (\"employee_id\" = 2)">
[2] pry(main)> result.frozen?
=> true
[3] pry(main)> result.singleton_class.frozen?
=> false
[4] pry(main)> result.singleton_class.include(EpulseNormalization)
=> #<Class:#<Sequel::Postgres::Dataset:0x007feff0903660>>
But in Ruby 2.4.2 it appears the singleton_class
is being returned as frozen and we can no longer extend it. Is there a new way of extending the singleton that I should be using??
[1] pry(main)> result = EpulseDB::Employee.where(employee_id: 2)
=> #<Sequel::Postgres::Dataset: "SELECT * FROM \"employee\" WHERE (\"employee_id\" = 2)">
[2] pry(main)> result.frozen?
=> true
[3] pry(main)> result.singleton_class.frozen?
=> true
[4] pry(main)> result.singleton_class.include(EpulseNormalization)
RuntimeError: can't modify frozen object
from (pry):4:in `append_features'