def method_missing(sym, *args)
      chars = sym.to_s
      if chars =~ self.class.class_variable_get(:@@SWIZZLE_CHARS)
        mapping = self.class.class_variable_get(:@@SWIZZLE_MAPPING)
        arg_indices = chars.each_char.map {
          |char|
          index = mapping[char]
          if index.nil?
            raise ArgumentError, "No index mapping for swizzle character #{char} found"
          end
          index
        }
        swizzle_klass = mapping[chars.length]

        if swizzle_klass.nil?
          raise ArgumentError, "No swizzle class defined for #{chars.length} components"
        end

        self.class.class_exec(arg_indices, swizzle_klass) {
          |indices, klass|
          define_method(sym) {
            klass.new(indices.map { |index| self.fetch(index) })
          }
        }
        return self.send(sym)
      end

      __under_method_missing__ sym, *args
    end
def method_missing(sym, *args)
      chars = sym.to_s
      if chars =~ self.class.class_variable_get(:@@SWIZZLE_CHARS)
        mapping = self.class.class_variable_get(:@@SWIZZLE_MAPPING)
        arg_indices = chars.each_char.map {
          |char|
          index = mapping[char]
          if index.nil?
            raise ArgumentError, "No index mapping for swizzle character #{char} found"
          end
          index
        }
        swizzle_klass = mapping[chars.length]

        if swizzle_klass.nil?
          raise ArgumentError, "No swizzle class defined for #{chars.length} components"
        end

        self.class.class_exec(arg_indices, swizzle_klass) {
          |indices, klass|
          define_method(sym) {
            klass.new(indices.map { |index| self.fetch(index) })
          }
        }
        return self.send(sym)
      end

      __under_method_missing__ sym, *args
    end
Generates a swizzle function according to a class's @@SWIZZLE_CHARS and
 @@SWIZZLE_MAPPING class variables.

 Overrides old method_missing implementation. The old implementation is
 aliased as \_\_under_method_missing__ and called when no swizzle function
 can be generated for a symbol.