Class: Rust::S4Class

Inherits:
RustDatatype show all
Defined in:
lib/rust/core/types/s4class.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RustDatatype

pull_priority, #r_mirror, #r_mirror_to

Constructor Details

#initialize(variable_name, klass, slots) ⇒ S4Class

Returns a new instance of S4Class.



23
24
25
26
27
28
# File 'lib/rust/core/types/s4class.rb', line 23

def initialize(variable_name, klass, slots)
    @klass = klass
    @slots = slots
    
    self.r_mirror_to(variable_name)
end

Class Method Details

.can_pull?(type, klass) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/rust/core/types/s4class.rb', line 5

def self.can_pull?(type, klass)
    return type == "S4"
end

.pull_variable(variable, type, klass) ⇒ Object



9
10
11
12
13
# File 'lib/rust/core/types/s4class.rb', line 9

def self.pull_variable(variable, type, klass)
    slots = [Rust._pull("names(getSlots(\"#{klass}\"))")].flatten
    
    return S4Class.new(variable, klass, slots)
end

Instance Method Details

#[](key) ⇒ Object Also known as: |

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
# File 'lib/rust/core/types/s4class.rb', line 30

def [](key)
    raise ArgumentError, "Unknown slot `#{key}` for class `#@klass`" unless @slots.include?(key)
    
    Rust.exclusive do
        return Rust["#{self.r_mirror}@#{key}"]
    end
end

#[]=(key, value) ⇒ Object

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
# File 'lib/rust/core/types/s4class.rb', line 39

def []=(key, value)
    raise ArgumentError, "Unknown slot `#{key}` for class `#@klass`" unless @slots.include?(key)
    
    Rust.exclusive do
        return Rust["#{self.r_mirror}@#{key}"] = value
    end
end

#class_nameObject



51
52
53
# File 'lib/rust/core/types/s4class.rb', line 51

def class_name
    @klass
end

#inspectObject



55
56
57
# File 'lib/rust/core/types/s4class.rb', line 55

def inspect
    return "<S4 instance of #@klass, with slots #@slots>"
end

#load_in_r_as(variable_name) ⇒ Object



15
16
17
# File 'lib/rust/core/types/s4class.rb', line 15

def load_in_r_as(variable_name)
    Rust._eval("#{variable_name} <- #{self.r_mirror}")
end

#r_hashObject



19
20
21
# File 'lib/rust/core/types/s4class.rb', line 19

def r_hash
    "immutable"
end

#slotsObject



47
48
49
# File 'lib/rust/core/types/s4class.rb', line 47

def slots
    @slots
end