класс ActiveSupport::OrderedHash
ActiveSupport::OrderedHash реализует хеш-таблицу, сохраняющую порядок вставки.
oh = ActiveSupport::OrderedHash.new oh[:a] = 1 oh[:b] = 2 oh.keys # => [:a, :b], this order is guaranteed
Также, отображает функцию omap для файлов YAML (см. yaml.org/type/omap.html) для поддержки упорядоченных элементов при загрузке из YAML.
ActiveSupport::OrderedHash имеет пространство имён, чтобы предотвратить конфликты с другими реализациями.
Открытые методы экземпляра
# File activesupport/lib/active_support/ordered_hash.rb, line 27
def encode_with(coder)
coder.represent_seq '!omap', map { |k,v| { k => v } }
end Возвращает true, чтобы убедиться, что этот хеш может быть извлечён с помощью Array#extract_options!
# File activesupport/lib/active_support/ordered_hash.rb, line 44 def extractable_options? true end
# File activesupport/lib/active_support/ordered_hash.rb, line 39 def nested_under_indifferent_access self end
# File activesupport/lib/active_support/ordered_hash.rb, line 35
def reject(*args, &block)
dup.tap { |hash| hash.reject!(*args, &block) }
end # File activesupport/lib/active_support/ordered_hash.rb, line 31
def select(*args, &block)
dup.tap { |hash| hash.select!(*args, &block) }
end # File activesupport/lib/active_support/ordered_hash.rb, line 23 def to_yaml_type "!tag:yaml.org,2002:omap" end
© 2004–2016 David Heinemeier Hansson
Licensed under the MIT License.