Method: YARD::Tags::Library.define_tag

Defined in:
lib/yard/tags/library.rb

.define_tag(label, tag, meth = nil) ⇒ Object

Convenience method to define a new tag using one of Tag‘s factory methods, or the regular DefaultFactory#parse_tag factory method if none is supplied.

Parameters:

  • tag (#to_s)

    the tag name to create

  • meth (#to_s, Class<Tag>) (defaults to: nil)

    the Tag factory method to call when creating the tag or the name of the class to directly create a tag for


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/yard/tags/library.rb', line 119

def define_tag(label, tag, meth = nil)
  if meth.is_a?(Class) && Tag > meth
    class_eval <<-eof, __FILE__, __LINE__
      def #{tag}_tag(text)
        #{meth}.new(#{tag.inspect}, text)
      end
    eof
  else
    class_eval <<-eof, __FILE__, __LINE__
      def #{tag}_tag(text)
        send_to_factory(#{tag.inspect}, #{meth.inspect}, text)
      end
    eof
  end

  @labels ||= SymbolHash.new(false)
  @labels.update(tag => label)
  @factory_methods ||= SymbolHash.new(false)
  @factory_methods.update(tag => meth)
  tag
end