Class: Rust::List
Class Method Summary
collapse
Instance Method Summary
collapse
pull_priority, #r_hash, #r_mirror, #r_mirror_to
Constructor Details
#initialize(klass, names = []) ⇒ List
Returns a new instance of List.
30
31
32
33
34
|
# File 'lib/rust/core/types/list.rb', line 30
def initialize(klass, names = [])
@data = {}
@names = names
@klass = klass
end
|
Class Method Details
.can_pull?(type, klass) ⇒ Boolean
5
6
7
|
# File 'lib/rust/core/types/list.rb', line 5
def self.can_pull?(type, klass)
return type == "list"
end
|
.pull_variable(variable, type, klass) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/rust/core/types/list.rb', line 9
def self.pull_variable(variable, type, klass)
return List.new(klass) if Rust._pull("length(#{variable})") == 0
names = [Rust["names(#{variable})"]].flatten
length = Rust["length(#{variable})"]
list = List.new(klass, names)
for i in 0...length
list[i] = Rust["#{variable}[[#{i + 1}]]"]
end
return list
end
|
Instance Method Details
#[](key) ⇒ Object
Also known as:
|
36
37
38
39
40
|
# File 'lib/rust/core/types/list.rb', line 36
def [](key)
key = get_key(key)
return @data[key]
end
|
#[]=(key, value) ⇒ Object
43
44
45
46
47
|
# File 'lib/rust/core/types/list.rb', line 43
def []=(key, value)
key = get_key(key)
return @data[key] = value
end
|
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/rust/core/types/list.rb', line 53
def inspect
result = ""
values_inspected = @data.map { |k, v| [k, v.inspect.split("\n").map { |l| " " + l }.join("\n")] }.to_h
max_length = [values_inspected.map { |k, v| v.split("\n").map { |line| line.length }.max.to_i }.max.to_i, 100].min
@data.keys.each do |i|
result << "-" * max_length + "\n"
result << (@names[i] || "[[#{i}]]") + "\n"
result << values_inspected[i] + "\n"
end
result << "-" * max_length
return result
end
|
#load_in_r_as(variable_name) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/rust/core/types/list.rb', line 23
def load_in_r_as(variable_name)
Rust._eval("#{variable_name} <- list()")
@data.each do |key, value|
Rust["#{variable_name}[[#{key + 1}]]"] = value
end
end
|
49
50
51
|
# File 'lib/rust/core/types/list.rb', line 49
def names
@names
end
|