Class: Rust::Struct

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/rust_require/struct.rb

Instance Method Summary collapse

Instance Method Details

#[](field) ⇒ Object

TODO maybe type & bounds checking?



8
9
10
11
12
13
14
15
16
# File 'lib/rust_require/struct.rb', line 8

def [](field)
  if field.respond_to? :to_sym
    field = field.to_sym
  elsif field.respond_to? :to_s
    field = field.to_s.to_sym
  end

  old_get(field)
end

#[]=(field, obj) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rust_require/struct.rb', line 18

def []=(field, obj)
  if field.respond_to? :to_sym
    field = field.to_sym
  elsif field.respond_to? :to_s
    field = field.to_s.to_sym
  end

  old_set(field, obj)
end

#old_getObject



3
# File 'lib/rust_require/struct.rb', line 3

alias_method :old_get, :"[]"

#old_setObject



4
# File 'lib/rust_require/struct.rb', line 4

alias_method :old_set, :"[]="