T
Tassilo Horn
Hi,
I wrote a nice translation app (RDictCc, [1]), which uses GDBM. So
currently it's like
,----
| require 'gdbm'
|
| GDBM.open(...) do
| foo
| end
`----
Now I want to let it use QDBM if it's available, else fall back on
GDBM. But what's the most idiomatic way to do this?
Currently I'd go like this:
,----
| begin
| require 'qdbm'
| db_backend = :qdbm
| rescue LoadError
| require 'gdbm'
| db_backend = :gdbm
| end
|
| if db_backend == :qdbm
| QDBM.open(...) do |dbm|
| ...
| end
| else
| GDBM.open(...) do |dbm|
| ...
| end
| end
`----
But the if-statement seems smelly, since both GDBM and QDBM respond to
class method open(). But something like
,----
| require 'qdbm'
| db_backend = QDBM.class
| ...
| db_backend.open
`----
doesn't work.
Any hints?
Footnotes:
[1] http://www.uni-koblenz.de/~heimdall/apps.html
I wrote a nice translation app (RDictCc, [1]), which uses GDBM. So
currently it's like
,----
| require 'gdbm'
|
| GDBM.open(...) do
| foo
| end
`----
Now I want to let it use QDBM if it's available, else fall back on
GDBM. But what's the most idiomatic way to do this?
Currently I'd go like this:
,----
| begin
| require 'qdbm'
| db_backend = :qdbm
| rescue LoadError
| require 'gdbm'
| db_backend = :gdbm
| end
|
| if db_backend == :qdbm
| QDBM.open(...) do |dbm|
| ...
| end
| else
| GDBM.open(...) do |dbm|
| ...
| end
| end
`----
But the if-statement seems smelly, since both GDBM and QDBM respond to
class method open(). But something like
,----
| require 'qdbm'
| db_backend = QDBM.class
| ...
| db_backend.open
`----
doesn't work.
Any hints?
Footnotes:
[1] http://www.uni-koblenz.de/~heimdall/apps.html