Overriding setter method for attr_accessor when including InstanceMethods module?

Call order in Ruby starts with normal instance methods before proceeding to methods of included modules and superclass methods. The never_expire method created by attr_accessor winds up being an instance method, so it's called rather than the InstanceMethods module's method. If you use attr_reader instead, so that no never_expire instance method gets defined, it will work as you intend.

Call order in Ruby starts with normal instance methods before proceeding to methods of included modules and superclass methods. The never_expire= method created by attr_accessor winds up being an instance method, so it's called rather than the InstanceMethods module's method. If you use attr_reader instead, so that no never_expire= instance method gets defined, it will work as you intend.

That said, you're making things more complicated than they need to be with those extra ClassMethods and InstanceMethods modules. Just use modules like they were intended: module HasPublishDates attr_reader :never_expire def never_expire=(value) @never_expire = ActiveRecord::ConnectionAdapters::Column. Value_to_boolean(value) end end class MyModel.

Well, you could just not bother with the attr_accessor... after all, you'd just need to add: def never_expire @never_expire end and it'd work just fine without that. If it's an actual AR column on the db, though, I'd recommend using set_attribute(:never_expire, ActiveRecord::ConnectionAdapters::Column.... rather than the @never_expire variable. You'd also not need the attr_accessor in that case.

A a final option, you could use class-eval just on the include statement eg: module ClassMethods def has_publish_dates(*args) attr_accessor :never_expire class_eval do include InstanceMethods end end end.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions