Ruby 1.8.7 リファレンスマニュアル > ライブラリ一覧 > digestライブラリ > Digest::Baseクラス

class Digest::Base

クラスの継承リスト: Digest::Base < Digest::Instance < Digest::Class < Object < Kernel

要約

すべての Digest::XXX クラスの基底クラス。

例えば、MD5 値を得るには以下のようにする。

require 'digest/md5'

p Digest::MD5.hexdigest('abc')               #=> '900150983cd24fb0d6963f7d28e17f72'
p Digest::MD5.file('ruby-1.8.5.tar.gz').to_s #=> '3fbb02294a8ca33d4684055adba5ed6f'

すべての Digest::XXX クラスは以下の共通インタフェースを持つ。

特異メソッド

定義 説明
digest(str)

与えられた文字列に対するハッシュ値を文字列で返す。 new(str).digest と等価。

file(path) -> object

新しいダイジェストオブジェクトを生成し、 ファイル名 file で指定したファイルの内容を読み込み、 そのダイジェストオブジェクトを返します。

hexdigest(str)

与えられた文字列に対するハッシュ値を、ASCIIコードを使って 16進数の列を示す文字列にエンコードして返す。 new(str).hexdigest と等価。

new

新しいダイジェストオブジェクトを生成する。

インスタンスメソッド

定義 説明
update(str)
self << str

文字列を追加する。self を返す。 複数回updateを呼ぶことは文字列を連結してupdateを呼ぶことと等しい。 すなわち m.update(a); m.update(b) は m.update(a + b) と、 m << a << b は m << a + b とそれぞれ等価 である。

self == md

与えられたダイジェストオブジェクトと比較する。

self == str

与えられた文字列を hexdigest 値と見て、自身の hexdigest 値と比較する。

block_length -> Integer

ダイジェストのブロック長を取得します。 例えば、Digest::MD5であれば64、Digest::SHA512であれば128です。

dup
clone

ダイジェストオブジェクトの複製を作る。

digest -> String

updateや<<によって追加した文字列に対するハッシュ値を文字列で返します。

digest! -> String

updateや<<によって追加した文字列に対するハッシュ値を文字列で返します。 Digest::Base#digestと違い、 メソッドの処理後、 オブジェクトの状態を初期状態(newした直後と同様の状態)に戻します。

digest_length -> Integer
length -> Integer
size -> Integer

ダイジェストのハッシュ値のバイト長を取得する。 例えば、Digest::MD5であれば16、Digest::SHA1であれば20です。

file(path) -> self

ファイル名 file で指定したファイルの内容を読み込んでダイジェストを更新し、 オブジェクト自身を返します。

hexdigest -> String
to_s -> String

updateや<<によって追加した文字列に対するハッシュ値を、 ASCIIコードを使って16進数の列を示す文字列にエンコードして返す。

hexdigest! -> String

updateや<<によって追加した文字列に対するハッシュ値を、 ASCIIコードを使って16進数の列を示す文字列にエンコードして返します。 Digest::Base#hexdigestと違い、 メソッドの処理後、 オブジェクトの状態を初期状態(newした直後と同様の状態)に戻します。

reset -> self

オブジェクトの状態を初期状態(newした直後と同様の状態)に戻し、 オブジェクト自身を返します。

継承したメソッド

=== =~ __id__ __send__ _dump class dclone display enum_for eql? equal? extend freeze frozen? hash initialize initialize_copy inspect instance_eval instance_exec instance_of? instance_variable_defined? instance_variable_get instance_variable_set instance_variables is_a? marshal_dump marshal_load method method_missing methods nil? pretty_inspect pretty_print pretty_print_cycle pretty_print_inspect pretty_print_instance_variables private_methods protected_methods public_methods remove_instance_variable respond_to? singleton_method_added singleton_method_removed singleton_method_undefined singleton_methods taint tainted? tap to_a to_ary to_hash to_int to_io to_proc to_regexp to_str to_yaml to_yaml_properties to_yaml_style untaint