Class: Rust::S4Class
- Inherits:
-
RustDatatype
- Object
- RustDatatype
- Rust::S4Class
- Defined in:
- lib/rust/core/types/s4class.rb
Overview
Mirror for the S4 class in R.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ Object
(also: #|)
Returns the slot
key
for the class name (klass
). -
#[]=(key, value) ⇒ Object
Returns the slot
key
for the class name (klass
) withvalue
. -
#class_name ⇒ Object
Returns the class name.
-
#initialize(variable_name, klass, slots) ⇒ S4Class
constructor
Creates a new S4 element, given its
variable_name
, class name (klass
), andslots
. - #inspect ⇒ Object
- #load_in_r_as(variable_name) ⇒ Object
- #r_hash ⇒ Object
-
#slots ⇒ Object
Returns the slots.
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
9 10 11 |
# File 'lib/rust/core/types/s4class.rb', line 9 def self.can_pull?(type, klass) return type == "S4" end |
Instance Method Details
#[](key) ⇒ Object Also known as: |
Returns the slot key
for the class name (klass
).
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
.
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_name ⇒ Object
Returns the class name.
70 71 72 |
# File 'lib/rust/core/types/s4class.rb', line 70 def class_name @klass end |
#inspect ⇒ Object
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_hash ⇒ Object
23 24 25 |
# File 'lib/rust/core/types/s4class.rb', line 23 def r_hash "immutable" end |
#slots ⇒ Object
Returns the slots.
63 64 65 |
# File 'lib/rust/core/types/s4class.rb', line 63 def slots @slots end |