40 lines
542 B
Ruby
40 lines
542 B
Ruby
class Sensitive
|
|
alias_method :eql?, :==
|
|
alias_method :equal?, :==
|
|
|
|
def initialize(v, ch: "*", head: 2, tail: 2)
|
|
@v = v
|
|
@ch = ch
|
|
@head = head
|
|
@tail = tail
|
|
end
|
|
|
|
def mask(v)
|
|
+"".concat(v[0, @head], @ch * (v.length - (@head + @tail)), v[-@tail, @tail])
|
|
end
|
|
|
|
def unwrap
|
|
@v
|
|
end
|
|
|
|
def length
|
|
@v.length
|
|
end
|
|
|
|
def to_s
|
|
mask @v
|
|
end
|
|
|
|
def inspect
|
|
"#<#{self.class.name} @v=#{wrap}>"
|
|
end
|
|
|
|
def hash
|
|
@v.hash
|
|
end
|
|
|
|
def ==(other)
|
|
other.is_a?(Sensitive) && other.hash == hash
|
|
end
|
|
end
|