As an alternative on using inheritance, why not consider a simple Singleton pattern? This could make your models cleaner, by separating the responsibility outside your classes. And eliminating the need for inheritance.
The example below illustrates this. Only one, single instance of the DataManager class can exist. So, you'll only instantiate it once - but can use it everywhere:
require 'singleton' class DataManager include Singleton attr_accessor :last_run_query def initialize() if @client.nil? p "Initialize the Mysql client here - note that this'll only be called once..." end end def query(args) # do your magic here @last_run_query = args end end
Next, calling it using the .instance accessor is a breeze - and will always point to one single instance, like so:
# Fetch, or create a new singleton instance first = DataManager.instance first.query('drop table mother') p first.last_run_query # Again, fetch or create a new instance # this'll actually just fetch the first instance from above second = DataManager.instance p second.last_run_query # last line prints: "drop table mother"
For the record, the Singleton pattern can have some downsides and using it frequently results in a never-ending debate on whether you should use it or not. But in my opinion it's a decent alternative to your specific question.