[redland-dev] Suggestions and queries about Ruby bindings

Dave Beckett dave at dajobe.org
Mon Oct 31 00:10:36 GMT 2005


Matthew Denner wrote:
> Hi,
> 
> I've been playing about a bit with the Redland Ruby bindings for a
> while now and I'm starting to build up a couple of "fixes" (misnamed
> constants like Redland::OWL::OWL instead of Redland::OWL::OWLNS,
> missing includes, and some more Ruby-like code inside some of the
> methods).  I'll be passing these back when I get them finished off if
> they're wanted.

That sounds great.

> One of the areas I'm currently wandering through is
> Redland::QueryResults and have a couple of questions:
> 
> When you access a binding value and it is a resource, should this be
> an instance of the Redland::Resource class?  I only ask because at the
> moment it's returning plain Redland::Node instances and I'm wondering
> if that's "right" (not, "right that's what the code does" but "right
> that's semantically correct").

Resource - http://librdf.org/docs/rdoc/classes/Redland/Resource.html
looks like some kind of wrapper for Node to provide some additional 
functionality.  I'm not sure if it's what should be done by default.

> Also, isn't it more sensible for the 'bindings' method to return a
> Hash, from binding name to binding value, rather than an array (which
> it says it does but it doesn't)?
> If this is sensible then you can add an 'each' method that does this:
> 
> class QueryResults
>   def each
>     while !self.finished?
>       yield(bindings())
>       self.next
>     end
>   end
> end
> 
> So that you can do:
> 
> Query.new("RDQL query with binding").each do |b|
>   puts b['binding']
> end
> 
> Which feels more Ruby-ish, if there is such a thing.  It also means
> that it might be possible to use the Enumerable mixin and get a load
> of fairly useful methods.
> 
> Just thinking out loud really.


+1 for more Ruby-ish and especially working with do |x| .. end

What do you get returned for each key:value item in the hash?  a string 
key and a redland node value?  My Ruby's a bit rusty.

Dave





More information about the redland-dev mailing list