From: Robert Dober Date: 2007-01-18T22:34:04+09:00 Subject: Re: Hash#open! / Hash#close! ------=_Part_140862_22730577.1169127242128 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 1/18/07, Trans wrote: > > > T > > > ps. i came across an oddity while messing with this: > > irb(main):019:0> q =3D {} > =3D> {} > irb(main):020:0> q.sort_by > =3D> [] > irb(main):021:0> q[:a] =3D 1 > =3D> 1 > irb(main):022:0> q.sort_by > LocalJumpError: no block given > from (irb):22:in `sort_by' > from (irb):22 > from =03:0 > ruby 1.8.4 on debian Hmm is it really an oddity (I have the same behavior on 1.8.5/debian)? An empty hash sort just cannot apply the block to any elements, but I gues= s you know that ;). Would you prefer that sort_by just checks for the presence of a block anyway? I gotto think a lot about the rest you have written most interesting stuff, just some very quick thoughts * There are structs you know ;) * #open! could return self so that one can write h=3D{:value=3D>42}.open! #close! should than too for symmetry. * Would it not be better not to hide a method in case the hash has no key? That would be a mess right? One would not know if h.size is 1 because of h[:size]=3D1 or h=3D{:a=3D>1}.open! * I'd like to use #open! behind the scenes with a block form like class Hash def use_opened &blk open! blk.call(self) if blk close! end end or even class Hash def in_context &blk open! instance_eval &blk ..... Conclusion: Basically it is a nice idea but maybe you really want a struct. I would not think it should be in the core but in an extension like facet of course it might be spot on ;) In any case that is the kind of post which make this ML so much fun and education. Cheers Robert --=20 "The best way to predict the future is to invent it." - Alan Kay ------=_Part_140862_22730577.1169127242128--