Class: Rangeable::Slot

Inherits:
Struct
  • Object
show all
Defined in:
lib/rangeable/slot.rb

Overview

Thin wrapper returned by ‘Rangeable#[]`. Wraps the active-element list at a single coordinate so we can grow the surface (e.g. add `count`, `transitions`, etc.) without changing the public type.

‘objs` is always a frozen `Array` of elements ordered by first-insert `ord(e)` ascending (RFC §4.5). We use a `Struct` (rather than a plain class) because the hot-path call sites are `r.objs` and the Struct accessor is materially faster than going through `attr_reader` + an ivar in MRI.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objsObject

Returns the value of attribute objs

Returns:

  • (Object)

    the current value of objs



13
14
15
# File 'lib/rangeable/slot.rb', line 13

def objs
  @objs
end

Instance Method Details

#each(&block) ⇒ Object



24
25
26
# File 'lib/rangeable/slot.rb', line 24

def each(&block)
  objs.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rangeable/slot.rb', line 14

def empty?
  objs.empty?
end

#inspectObject



32
33
34
# File 'lib/rangeable/slot.rb', line 32

def inspect
  "#<Rangeable::Slot objs=#{objs.inspect}>"
end

#sizeObject Also known as: count, length



18
19
20
# File 'lib/rangeable/slot.rb', line 18

def size
  objs.size
end

#to_aObject



28
29
30
# File 'lib/rangeable/slot.rb', line 28

def to_a
  objs.dup
end