def method_missing(sym, *args, &block)
      s = sym.to_s
      action = s[-1]
      # Try to match the method against a tag from the dictionary:
      tag = LIBRARY.as_tag(s) || LIBRARY.as_tag(s[0..-2])
      if tag
        if action == '?'
          # Query:
          return self.exists?(tag)
        elsif action == '='
          # Assignment:
          unless args.length==0 || args[0].nil?
            # What kind of element to create?
            if tag == 'FFFE,E000'
              return self.add_item
            elsif LIBRARY.element(tag).vr == 'SQ'
              return self.add(Sequence.new(tag))
            else
              return self.add(Element.new(tag, *args))
            end
          else
            return self.delete(tag)
          end
        else
          # Retrieval:
          return self[tag]
        end
      end
      # Forward to Object#method_missing:
      super
    end
def method_missing(sym, *args, &block)
      s = sym.to_s
      action = s[-1]
      # Try to match the method against a tag from the dictionary:
      tag = LIBRARY.as_tag(s) || LIBRARY.as_tag(s[0..-2])
      if tag
        if action == '?'
          # Query:
          return self.exists?(tag)
        elsif action == '='
          # Assignment:
          unless args.length==0 || args[0].nil?
            # What kind of element to create?
            if tag == 'FFFE,E000'
              return self.add_item
            elsif LIBRARY.element(tag).vr == 'SQ'
              return self.add(Sequence.new(tag))
            else
              return self.add(Element.new(tag, *args))
            end
          else
            return self.delete(tag)
          end
        else
          # Retrieval:
          return self[tag]
        end
      end
      # Forward to Object#method_missing:
      super
    end
Handles missing methods, which in our case is intended to be dynamic
 method names matching DICOM elements in the dictionary.

 When a dynamic method name is matched against a DICOM element, this method:
 * Returns the element if the method name suggests an element retrieval, and the element exists.
 * Returns nil if the method name suggests an element retrieval, but the element doesn't exist.
 * Returns a boolean, if the method name suggests a query (?), based on whether the matched element exists or not.
 * When the method name suggests assignment (=), an element is created with the supplied arguments, or if the argument is nil, the element is deleted.

 * When a dynamic method name is not matched against a DICOM element, and the method is not defined by the parent, a NoMethodError is raised.

 @param [Symbol] sym a method name