class YARD::Handlers::Ruby::Legacy::ClassConditionHandler

@since 0.5.4
(see Ruby::ClassConditionHandler)
frozen_string_literal: true

def parse_condition

Other tags:
    Since: - 0.5.5

Returns:
  • (true, false, nil) - true if the condition can be definitely
def parse_condition
  condition = nil
  # Right now we can handle very simple unary conditions like:
  #   if true
  #   if false
  #   if 0
  #   if 100 (not 0)
  #   if defined? SOME_CONSTANT
  #
  # The last case will do a lookup in the registry and then one
  # in the Ruby world (using eval).
  case statement.tokens[1..-1].to_s.strip
  when /^(\d+)$/
    condition = $1 != "0"
  when /^defined\?\s*\(?\s*([A-Za-z0-9:_]+?)\s*\)?$/
    # defined? keyword used, let's see if we can look up the name
    # in the registry, then we'll try using Ruby's powers. eval() is not
    # *too* dangerous here since code is not actually executed.
    name = $1
    obj = YARD::Registry.resolve(namespace, name, true)
    begin
      condition = true if obj || Object.instance_eval("defined? #{name}")
    rescue SyntaxError, NameError
      condition = false
    end
  when "true"
    condition = true
  when "false"
    condition = false
  end
  if TkUNLESS === statement.tokens.first
    condition = !condition unless condition.nil?
  end
  condition
end

def parse_else_block

Other tags:
    Since: - 0.5.5
def parse_else_block
  return unless statement.block
  stmtlist = YARD::Parser::Ruby::Legacy::StatementList
  stmtlist.new(statement.block).each do |stmt|
    next unless TkELSE === stmt.tokens.first
    push_state(:visibility => visibility) do
      parser.process(stmtlist.new(stmt.block))
    end
  end
end

def parse_then_block

Other tags:
    Since: - 0.5.5
def parse_then_block
  parse_block(:visibility => visibility)
end