Class: Rust::S4Class

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

Overview

Mirror for the S4 class in R.

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

Creates a new S4 element, given its variable_name, class name (klass), and slots.



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

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)


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

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

.pull_variable(variable, type, klass) ⇒ Object



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

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: |

Returns the slot key for the class name (klass).

Raises:

  • (ArgumentError)


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

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

Returns the slot key for the class name (klass) with value.

Raises:

  • (ArgumentError)


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

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

Returns the class name.



70
71
72
# File 'lib/rust/core/types/s4class.rb', line 70

def class_name
    @klass
end

#inspectObject



74
75
76
# File 'lib/rust/core/types/s4class.rb', line 74

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

#load_in_r_as(variable_name) ⇒ Object



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

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

#r_hashObject



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

def r_hash
    "immutable"
end

#slotsObject

Returns the slots.



63
64
65
# File 'lib/rust/core/types/s4class.rb', line 63

def slots
    @slots
end