класс ActiveSupport::OrderedOptions
Обычно пары ключ-значение обрабатываются примерно так:
h = {}
h[:boy] = 'John'
h[:girl] = 'Mary'
h[:boy] # => 'John'
h[:girl] # => 'Mary'
Используя OrderedOptions, код выше можно сократить до:
h = ActiveSupport::OrderedOptions.new h.boy = 'John' h.girl = 'Mary' h.boy # => 'John' h.girl # => 'Mary'
Публичные методы экземпляра
Вызывает метод суперкласса
# File activesupport/lib/active_support/ordered_options.rb, line 25 def [](key) super(key.to_sym) end
Также алиасирован как: _get
Вызывает метод суперкласса
# File activesupport/lib/active_support/ordered_options.rb, line 21 def []=(key, value) super(key.to_sym, value) end
_get(ключ)
Псевдоним для: []
# File activesupport/lib/active_support/ordered_options.rb, line 29
def method_missing(name, *args)
name_string = name.to_s
if name_string.chomp!('=')
self[name_string] = args.first
else
self[name]
end
end # File activesupport/lib/active_support/ordered_options.rb, line 38 def respond_to_missing?(name, include_private) true end
© 2004–2016 David Heinemeier Hansson
Licensed under the MIT License.