LogAn::AutoValueConvertHash: encode-bug fixed. encode and decode now are methods.
This commit is contained in:
parent
19929f069b
commit
261d0ddc5f
|
@ -58,26 +58,28 @@ end
|
||||||
|
|
||||||
class LogAn::AutoValueConvertHash
|
class LogAn::AutoValueConvertHash
|
||||||
include Enumerable
|
include Enumerable
|
||||||
attr_reader :decode, :encode, :source
|
attr_reader :source
|
||||||
|
|
||||||
def initialize source, encode = nil, each = nil, &decode
|
def initialize source, encode = nil, each = nil, &decode
|
||||||
@source, @encoder = source, decode.nil? ? encode || Marshal.method( :dump) : nil,
|
@source, @encode = source, decode.nil? ? encode || Marshal.method( :dump) : encode,
|
||||||
@each = each || source.method( :each) rescue NameError
|
@each, @decode = each, decode || Marshal.method( :restore)
|
||||||
@decode = decode || Marshal.method( :restore)
|
@each ||= source.method( :each) rescue NameError
|
||||||
|
define_method :encode, &@encode if @encode
|
||||||
|
define_method :decode, &@decode if @decode
|
||||||
end
|
end
|
||||||
|
|
||||||
def [] k
|
def [] k
|
||||||
@decode.call @source[k]
|
decode @source[k]
|
||||||
end
|
end
|
||||||
|
|
||||||
def []= k, v
|
def []= k, v
|
||||||
@source[k] = @encode.call v
|
@source[k] = encode v
|
||||||
end
|
end
|
||||||
|
|
||||||
def each *paras
|
def each *paras
|
||||||
return Enumerator.new self, :each unless block_given?
|
return Enumerator.new self, :each unless block_given?
|
||||||
@each.call *paras do |k, v|
|
@each.call *paras do |k, v|
|
||||||
yield k, @decode.call( v)
|
yield k, decode( v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue