Method: VirtualBox::COM::AbstractEnum.map
- Defined in:
- lib/virtualbox/com/abstract_enum.rb
.map(value = nil) ⇒ Object
Defines the mapping of int => symbol for the given Enum. The parameter to this can be an Array or Hash or anything which can be indexed with [] and an integer and returns a value of some sort. If value is left nil, it will return the current mapping
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/virtualbox/com/abstract_enum.rb', line 13 def map(value = nil) if value # Convert the array to a hash of equal structure if value.is_a?(Array) result = {} value.each_index do |i| result[value[i]] = i end value = result end # Store both the map and the reverse map since both lookups # are frequently used. @map = value @reverse_map = @map.invert end @map end |