Class: Array

Inherits:
Object show all
Defined in:
lib/decentworks/hexdigest_support/array.rb,
sig/decentworks/hexdigest_support/array.rbs

Instance Method Summary collapse

Instance Method Details

#to_hexdigest_source::String

ハッシュ値を求めるためのオリジナルの値

MEMO: 要素は#to_hexdigest_sourceではなく#to_hexdigest_inputで文字列化する。 値だけでは型が落ちるため、[:a] と ["a"]、[1] と ["1"] が同じ値になってしまう

MEMO: #to_hexdigest_inputは値を#inspectで引用・エスケープ済みのため、ここでの 追加の引用は不要。引用がないと、要素の文字列表現に区切り文字(,)が含まれる 場合に内容が異なる配列同士が同じ文字列になってしまう (例: ["a,b","c"] と ["a","b,c"] が衝突する)

Returns:

  • (::String)


15
16
17
18
19
20
21
22
23
# File 'lib/decentworks/hexdigest_support/array.rb', line 15

def to_hexdigest_source
  return "[]" if empty?

  map(&:to_hexdigest_input)
    .sort
    .join(",")
    .prepend("[")
    .concat("]")
end