method
[]
v3.2.13 -
Show latest stable
- Class:
ActiveSupport::OrderedHash
[](*args)public
No documentation available.
# File activesupport/lib/active_support/ordered_hash.rb, line 73
def self.[](*args)
ordered_hash = new
if (args.length == 1 && args.first.is_a?(Array))
args.first.each do |key_value_pair|
next unless (key_value_pair.is_a?(Array))
ordered_hash[key_value_pair[0]] = key_value_pair[1]
end
return ordered_hash
end
unless (args.size % 2 == 0)
raise ArgumentError.new("odd number of arguments for Hash")
end
args.each_with_index do |val, ind|
next if (ind % 2 != 0)
ordered_hash[val] = args[ind + 1]
end
ordered_hash
end 1Note
Example
NOTE: you pass all the keys and values in one long list:
fruit = ActiveSupport::OrderedHash[
'apple', 'Apple',
'banana', 'Banana',
'kiwi', 'Kiwi fruit',
]
fruit.keys => ["apple", "banana", "kiwi"]