Class: Prism::LibRubyParser::PrismString
Overview
This object represents a pm_string_t. We only use it as an opaque pointer, so it doesn’t have to be an FFI::Struct.
Constant Summary collapse
- SIZEOF =
:nodoc:
LibRubyParser.pm_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 pm_string_t pointer to the given block.
Instance Method Summary collapse
-
#initialize(pointer) ⇒ PrismString
constructor
A new instance of PrismString.
- #length ⇒ Object
- #read ⇒ Object
- #source ⇒ Object
Constructor Details
#initialize(pointer) ⇒ PrismString
Returns a new instance of PrismString.
142 143 144 |
# File 'lib/prism/ffi.rb', line 142 def initialize(pointer) @pointer = pointer end |
Instance Attribute Details
#pointer ⇒ Object (readonly)
Returns the value of attribute pointer.
140 141 142 |
# File 'lib/prism/ffi.rb', line 140 def pointer @pointer end |
Class Method Details
.with(filepath, &block) ⇒ Object
Yields a pm_string_t pointer to the given block.
159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/prism/ffi.rb', line 159 def self.with(filepath, &block) pointer = FFI::MemoryPointer.new(SIZEOF) begin raise unless LibRubyParser.pm_string_mapped_init(pointer, filepath) yield new(pointer) ensure LibRubyParser.pm_string_free(pointer) pointer.free end end |
Instance Method Details
#length ⇒ Object
150 151 152 |
# File 'lib/prism/ffi.rb', line 150 def length LibRubyParser.pm_string_length(pointer) end |
#read ⇒ Object
154 155 156 |
# File 'lib/prism/ffi.rb', line 154 def read source.read_string(length) end |
#source ⇒ Object
146 147 148 |
# File 'lib/prism/ffi.rb', line 146 def source LibRubyParser.pm_string_source(pointer) end |