[redland-dev] Suggestions and queries about Ruby bindings
Matthew Denner
matt.denner at gmail.com
Fri Oct 14 19:19:52 BST 2005
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.
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").
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.
Matt
More information about the redland-dev
mailing list