Class: NiceFFI::Struct
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- NiceFFI::Struct
- Defined in:
- lib/net-snmp2.rb
Overview
XXX
I just monkeypatched this to take a nil first argument. Seems to work
Should probably submit this as a patch
Direct Known Subclasses
Net::SNMP::Wrapper::Counter64, Net::SNMP::Wrapper::EnumList, Net::SNMP::Wrapper::IndexList, Net::SNMP::Wrapper::Module, Net::SNMP::Wrapper::ModuleImport, Net::SNMP::Wrapper::SnmpPdu, Net::SNMP::Wrapper::SnmpSession, Net::SNMP::Wrapper::TimeVal, Net::SNMP::Wrapper::Tree, Net::SNMP::Wrapper::VariableList
Instance Method Summary collapse
-
#initialize(val = nil, options = {}) ⇒ Struct
constructor
A new instance of Struct.
Constructor Details
#initialize(val = nil, options = {}) ⇒ Struct
Returns a new instance of Struct.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/net-snmp2.rb', line 47 def initialize( val = nil, ={} ) # Stores certain kinds of member values so that we don't need # to create a new object every time they are read. @member_cache = {} = {:autorelease => true}.merge!( ) case val when Hash super(FFI::Buffer.new(size)) init_from_hash( val ) # Read the values from a Hash. # Note: plain "Array" would mean FFI::Struct::Array in this scope. when ::Array super(FFI::Buffer.new(size)) init_from_array( val ) # Read the values from an Array. when String super(FFI::Buffer.new(size)) init_from_bytes( val ) # Read the values from a bytestring. when self.class super(FFI::Buffer.new(size)) init_from_bytes( val.to_bytes ) # Read the values from another instance. when FFI::Pointer, FFI::Buffer val = _make_autopointer( val, [:autorelease] ) # Normal FFI::Struct behavior to wrap the pointer. super( val ) when nil super(val) else raise TypeError, "cannot create new #{self.class} from #{val.inspect}" end end |