このコードの理解に苦戦しています。
class OrderedHash
def initialize()
@keys = Array.new()
@content = Hash.new()
end
def []=(key, value)
@content[key] = value
if !@keys.include?(key)
@keys << key
end
end
def delete(key)
@keys.delete(key)
@content.delete(key)
end
def keys()
@keys
end
def each()
@keys.each{|key|
yield(key, @content[key])
}
end
end
oh = OrderedHash.new()
oh["one"] = 1
oh["two"] = 2
oh["three"] = 3
oh["two"] = 4
p oh.keys()
oh.each{|key,value|
p [key, value]
}
配列とハッシュインスタンスをインスタンス変数(@keys,@content)に入れて
結局このコードは何をしているのでしょうか?
def
@content[key]
end
これは[]という名前のメソッドという事ですか?それとも引数を入れるものですか
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。