D
Daniel Schierbeck
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.digestsha1)
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).
Comments and constructive criticism are appreciated. Flames are not.
Cheers and remember Talk Like A Pirate Day the 19th,
Daniel
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.digestsha1)
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).
Comments and constructive criticism are appreciated. Flames are not.
Cheers and remember Talk Like A Pirate Day the 19th,
Daniel