Class: WR::ModListItems::Item

Inherits:
String
  • Object
show all
Defined in:
lib/wrb/listcommon.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, idx, str) ⇒ Item

Returns a new instance of Item.



14
15
16
17
18
# File 'lib/wrb/listcommon.rb', line 14

def initialize(target, idx, str)
  @target = target
  @index = idx
  super(str.to_s)
end

Instance Attribute Details

#indexObject

Returns the value of attribute index.



10
11
12
# File 'lib/wrb/listcommon.rb', line 10

def index
  @index
end

#targetObject

Returns the value of attribute target.



10
11
12
# File 'lib/wrb/listcommon.rb', line 10

def target
  @target
end

Class Method Details

.[](*args) ⇒ Object



12
# File 'lib/wrb/listcommon.rb', line 12

def self.[](*args) self.new(*args); end

Instance Method Details

#dataObject



27
28
29
30
31
32
33
34
# File 'lib/wrb/listcommon.rb', line 27

def data()
  if @target && @target.alive?
    dat = @target.send(:_getitemdata, @index, 0)
    ObjectSpace._id2ref(dat)
  else
    @data
  end
end

#data=(arg) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/wrb/listcommon.rb', line 20

def data=(arg)
  @data = arg
  if @target && @target.alive?
    oid = @data.__id__
    @target.send(:_setitemdata, @index, oid)
  end
end

#deleteObject



44
45
46
# File 'lib/wrb/listcommon.rb', line 44

def delete()
  @target.delete(@index)
end

#textObject



36
37
38
# File 'lib/wrb/listcommon.rb', line 36

def text()
  self.to_s
end

#text=(str) ⇒ Object



40
41
42
# File 'lib/wrb/listcommon.rb', line 40

def text=(str)
  @target[@index] = str.to_s
end

#to_aObject



48
# File 'lib/wrb/listcommon.rb', line 48

def to_a() [self, self.data]; end