Class: Twilic::Core::Session::MutableInternTable

Inherits:
Object
  • Object
show all
Defined in:
lib/twilic/core/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMutableInternTable

Returns a new instance of MutableInternTable.



362
363
364
365
# File 'lib/twilic/core/session.rb', line 362

def initialize
  @by_value = {}
  @by_id = []
end

Instance Attribute Details

#by_idObject (readonly)

Returns the value of attribute by_id.



360
361
362
# File 'lib/twilic/core/session.rb', line 360

def by_id
  @by_id
end

#by_valueObject (readonly)

Returns the value of attribute by_value.



360
361
362
# File 'lib/twilic/core/session.rb', line 360

def by_value
  @by_value
end

Instance Method Details

#clearObject



388
389
390
391
# File 'lib/twilic/core/session.rb', line 388

def clear
  @by_value = {}
  @by_id = []
end

#get_id(value) ⇒ Object



367
368
369
370
# File 'lib/twilic/core/session.rb', line 367

def get_id(value)
  id = @by_value[value]
  id ? [id, true] : [0, false]
end

#get_value(id) ⇒ Object



372
373
374
375
376
# File 'lib/twilic/core/session.rb', line 372

def get_value(id)
  return ["", false] if id >= @by_id.length

  [@by_id[id], true]
end

#register(value) ⇒ Object



378
379
380
381
382
383
384
385
386
# File 'lib/twilic/core/session.rb', line 378

def register(value)
  id = @by_value[value]
  return id if id

  id = @by_id.length
  @by_value[value] = id
  @by_id << value
  id
end