123456789_123456789_123456789_123456789_123456789_

Class: RBS::Location::WithChildren

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: RBS::Location
Defined in: lib/rbs/location.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(buffer:, start_pos:, end_pos:) ⇒ WithChildren

[ GitHub ]

  
# File 'lib/rbs/location.rb', line 150

def initialize(buffer:, start_pos:, end_pos:)
  super(buffer: buffer, start_pos: start_pos, end_pos: end_pos)

  @optional_children = {}
  @required_children = {}
end

Instance Attribute Details

#optional_children (readonly)

[ GitHub ]

  
# File 'lib/rbs/location.rb', line 148

attr_reader :required_children, :optional_children

#required_children (readonly)

[ GitHub ]

  
# File 'lib/rbs/location.rb', line 148

attr_reader :required_children, :optional_children

Instance Method Details

#[](key)

[ GitHub ]

  
# File 'lib/rbs/location.rb', line 163

def [](key)
  case
  when required_children.key?(_ = key)
    range = required_children[_ = key]
    Location.new(buffer: buffer, start_pos: range.begin, end_pos: range.end)
  when optional_children.key?(_ = key)
    range = required_children[_ = key] || optional_children[_ = key]
    if range
      Location.new(buffer: buffer, start_pos: range.begin, end_pos: range.end)
    end
  else
    raise "Unknown key given: `#{key}`"
  end
end

#initialize_copy(from)

[ GitHub ]

  
# File 'lib/rbs/location.rb', line 157

def initialize_copy(from)
  required_children.merge!(from.required_children)
  optional_children.merge!(from.optional_children)
  self
end

#merge_optional(hash)

[ GitHub ]

  
# File 'lib/rbs/location.rb', line 197

def merge_optional(hash)
  this = dup

  h = hash.transform_values do |value|
    case value
    when Range
      value
    when Location
      value.range
    else
      nil
    end
  end

  this.optional_children.merge!(h)

  this
end

#merge_required(hash)

[ GitHub ]

  
# File 'lib/rbs/location.rb', line 178

def merge_required(hash)
  this = dup

  h = hash.transform_values do |value|
    case value
    when Range
      value
    when Location
      value.range
    else
      raise
    end
  end

  this.required_children.merge!(h)

  this
end