Skip to content

Commit de014ba

Browse files
committed
Fix example code.
1 parent a81ed06 commit de014ba

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

guides/getting-started/readme.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,16 @@ require 'io/memory'
2828

2929
# Create a memory-mapped buffer
3030
IO::Memory.with(1024) do |handle|
31-
# Get a mapped IO::Buffer
32-
buffer = handle.map
33-
34-
# Write some data
35-
message = "Hello, World!"
36-
buffer.set_string(message, 0)
37-
38-
# Read data back
39-
result = buffer.get_string(0, message.length)
40-
puts result # => "Hello, World!"
41-
42-
# Access as IO object for traditional operations
43-
io = handle.io
44-
io.seek(0)
45-
io.write("Additional data")
31+
# Get a mapped IO::Buffer
32+
buffer = handle.map
33+
34+
# Write some data
35+
message = "Hello, World!"
36+
buffer.set_string(message, 0)
37+
38+
# Read data back
39+
result = buffer.get_string(0, message.length)
40+
puts result # => "Hello, World!"
4641
end # Automatically cleaned up
4742
```
4843

@@ -101,11 +96,11 @@ Handle platform-specific limitations gracefully:
10196
require 'io/memory'
10297

10398
begin
104-
# Some platforms may not support zero-size buffers
105-
handle = IO::Memory.new(0)
106-
buffer = handle.map
107-
handle.close
99+
# Some platforms may not support zero-size buffers
100+
handle = IO::Memory.new(0)
101+
buffer = handle.map
102+
handle.close
108103
rescue Errno::EINVAL => e
109-
puts "Zero-size buffers not supported: #{e.message}"
104+
puts "Zero-size buffers not supported: #{e.message}"
110105
end
111106
```

0 commit comments

Comments
 (0)