[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:02214] *DBM#invert

From: Clemens Hintze <c.hintze@...>
Date: 2000-03-28 12:09:10 UTC
List: ruby-talk #2214
There seems really to be a bug! DBM#invert will build a hash during
execution that contains all values as keys and the keys as
values. That means your demo 'mdb.each { ... }' should return:

1--a
2--b

But the bug seems to be that DBM#invert returns the DBM instance
itself instead of the new-created hash! So in your example DBM#each is
called instead of Hash#each.

The same is true for GDBM!

Applying following patches should help:



HTH,
\cle


ts writes:
> 
>  classes *DBM has a method #invert, but this method don't seem to work or
>  I've not understood how to use it :
> 
> pigeon% cat b.rb
> #!/usr/bin/ruby
> require "gdbm"
> dbm = GDBM.open("toto")
> dbm["a"] = "1"
> dbm["b"] = "2"
> dbm.each { |x, y| print "#{x}--#{y}\n" }
> mbd = dbm.invert
> mbd.each { |x, y| print "#{x}--#{y}\n" }
> dbm.close
> pigeon% b.rb
> a--1
> b--2
> a--1
> b--2
> pigeon% 
> 
> 
> Guy Decoux

-- 
Clemens Hintze  mailto: c.hintze@gmx.net

Attachments (2)

dbm.c.patch (420 Bytes, text/x-diff)
*** ext/dbm/dbm.c_sv	Tue Mar  7 09:37:52 2000
--- ext/dbm/dbm.c	Tue Mar 28 13:57:05 2000
***************
*** 262,268 ****
  	valstr = rb_tainted_str_new(val.dptr, val.dsize);
  	rb_hash_aset(hash, valstr, keystr);
      }
!     return obj;
  }
  
  static VALUE
--- 262,268 ----
  	valstr = rb_tainted_str_new(val.dptr, val.dsize);
  	rb_hash_aset(hash, valstr, keystr);
      }
!     return hash;
  }
  
  static VALUE
gdbm.c.patch (424 Bytes, text/x-diff)
*** ext/gdbm/gdbm.c_sv	Tue Mar  7 09:37:53 2000
--- ext/gdbm/gdbm.c	Tue Mar 28 13:57:37 2000
***************
*** 260,266 ****
  	valstr = rb_tainted_str_new(val.dptr, val.dsize);
  	rb_hash_aset(hash, valstr, keystr);
      }
!     return obj;
  }
  
  static VALUE
--- 260,266 ----
  	valstr = rb_tainted_str_new(val.dptr, val.dsize);
  	rb_hash_aset(hash, valstr, keystr);
      }
!     return hash;
  }
  
  static VALUE

In This Thread