Daniel Schierbeck wrote:
> I don't think this already exists, but if it does I apologise for your
> inconvenience.
>
> I propose that a method String#digest (or #checksum or whatever) is
> defined in the Digest class of the standard library.
>
>    # Current
>    digest = Digest::SHA1.new(str)
>
>    # Proposed
>    digest = str.digest(:sha1)
>
> This can be implemented fairly easily:
>
>    class String
>      def digest (type = :md5)
>        case type
>        when :md5
>          Digest::MD5.new(self)
>        when :sha1
>          Digest::SHA1.new(self)
>        end
>      end
>    end
>
> String#digest does not have to work like it does in my example. The
> key point here is that a message digest / hashsum should be a
> property of the string. I think it's the Ruby Way to Do It (TM).

Hm, on one hand I agree to you as this seems natural.  On the other hand
this introduces a dependency from String (a very basic class) to your
digest classes (not so basic).  Also, you would have to maintain
String#digest every time there is a new algorithm unless you do it like

def digest(algo) algo.new(self) end

"foo".digest(Digest::SHA1)

But something tells me it's not worth the effort...

> Cheers and remember Talk Like A Pirate Day the 19th,

What's that?  Do pirates actually talk?

Kind regards

    robert