Module: Typerb::VariableNameUtil

Defined in:
lib/typerb.rb

Class Method Summary collapse

Class Method Details

.get(c_loc) ⇒ Object

rubocop: disable Metrics/AbcSize screw this



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/typerb.rb', line 40

def get(c_loc) # rubocop: disable Metrics/AbcSize screw this
  where = c_loc[0]
  file = where.path
  line = where.lineno
  return unless File.exist?(file)

  code = File.read(file).lines[line - 1].strip
  node = RubyVM::AST.parse(code)
  if node.children.last.children.size == 3 && %i[type! not_nil!].include?(node.children.last.children[1]) # rubocop: disable Style/IfUnlessModifier, Style/GuardClause
    node.children.last.children.first.children.first
  end
end

.klasses_text(klasses) ⇒ Object



53
54
55
# File 'lib/typerb.rb', line 53

def klasses_text(klasses)
  klasses.size > 1 ? klasses.map(&:name).join(' or ') : klasses.first.name
end