# Writing a custom TreeModel

**URL:** <https://www.ruby-forum.com/t/writing-a-custom-treemodel/190439>\
**Category:** Ruby-Gnome 2\
**Created:** [June 20, 2010, 11:33am UTC](https://www.ruby-forum.com/t/writing-a-custom-treemodel/190439 "2010-06-20T11:33:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![niklas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@niklas](https://www.ruby-forum.com/u/niklas)\
**Post date:** [June 20, 2010, 11:33am UTC](https://www.ruby-forum.com/t/writing-a-custom-treemodel/190439/1 "2010-06-20T11:33:15Z")

</div>

Hi,  
I’m trying to implement a custom TreeModel. My primary reason for doing  
so is, that I don’t want to load all the data into a list/tree store,  
but only want to load it when the view actually tries to access it. The  
basic thing I tried was this:

class MyStore \< GLib::Object  
type\_register # I don’t know if this is needed ?  
include Gtk::TreeModel

def initialize  
super()  
# some stuff…  
end

# here I implement all the stuff from TreeModel.

end

Now there are a few problems:

- including Gtk::TreeModel raises this: “in `append\_features’: Not a  
subclass of GLib::Instantiatable (TypeError)”  
\*\* trying to track this down, I found the code that raises it:  
[Ruby-GNOME 2 download | SourceForge.net](http://ruby-gnome2.svn.sourceforge.net/viewvc/ruby-gnome2/ruby-gnome2/trunk/glib/src/rbgobj_typeinterface.c?revision=3776&view=markup)  
\*\* it seems clear to me that this is raises (as the klass passed into  
interface\_s\_append\_features is a class and not an object.  
GLib::Instantiatable is a ancestor of that class, but not of that  
class’s class)
- Not including Gtk::TreeModel (or extending with it in the initializer)  
gives me runtime errors from gtk:  
\*\* GLib-GObject-WARNING \*\*:invalid cast from `MyStore' to `GtkTreeModel’  
\*\* GLib-GObject-WARNING \*\*:IA\_\_g\_object\_new\_valist: invalid object type  
`MyStore' for value type `GtkTreeModel’

Can anyone explain me what I’m missing? Or is there maybe no way to  
write custom stores in ruby at all?  
I already brought this up in IRC, but no response.

– niklas
