Class: YARP::LibRubyParser::YPString
- Inherits:
-
Object
- Object
- YARP::LibRubyParser::YPString
- Defined in:
- lib/yarp/ffi.rb
Overview
This object represents a yp_string_t. We only use it as an opaque pointer, so it doesn’t have to be an FFI::Struct.
Constant Summary collapse
- SIZEOF =
LibRubyParser.yp_string_sizeof
Instance Attribute Summary collapse
-
#pointer ⇒ Object
readonly
Returns the value of attribute pointer.
Class Method Summary collapse
-
.with(filepath, &block) ⇒ Object
Yields a yp_string_t pointer to the given block.
Instance Method Summary collapse
-
#initialize(pointer) ⇒ YPString
constructor
A new instance of YPString.
- #length ⇒ Object
- #read ⇒ Object
- #source ⇒ Object
Constructor Details
#initialize(pointer) ⇒ YPString
140 141 142 |
# File 'lib/yarp/ffi.rb', line 140 def initialize(pointer) @pointer = pointer end |
Instance Attribute Details
#pointer ⇒ Object (readonly)
Returns the value of attribute pointer.
138 139 140 |
# File 'lib/yarp/ffi.rb', line 138 def pointer @pointer end |
Class Method Details
.with(filepath, &block) ⇒ Object
Yields a yp_string_t pointer to the given block.
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/yarp/ffi.rb', line 157 def self.with(filepath, &block) pointer = FFI::MemoryPointer.new(SIZEOF) begin raise unless LibRubyParser.yp_string_mapped_init(pointer, filepath) yield new(pointer) ensure LibRubyParser.yp_string_free(pointer) pointer.free end end |
Instance Method Details
#length ⇒ Object
148 149 150 |
# File 'lib/yarp/ffi.rb', line 148 def length LibRubyParser.yp_string_length(pointer) end |
#read ⇒ Object
152 153 154 |
# File 'lib/yarp/ffi.rb', line 152 def read source.read_string(length) end |
#source ⇒ Object
144 145 146 |
# File 'lib/yarp/ffi.rb', line 144 def source LibRubyParser.yp_string_source(pointer) end |