-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bindings/ruby): implement an IO like class
- Loading branch information
Showing
8 changed files
with
596 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module OpenDAL | ||
class IO | ||
# Reads all lines from the stream into an array. | ||
# Raises `EOFError` when the end of the file is reached. | ||
def readlines | ||
results = [] | ||
|
||
loop do | ||
results << readline | ||
rescue EOFError | ||
break | ||
end | ||
|
||
results | ||
end | ||
|
||
# Rewinds the stream to the beginning. | ||
def rewind | ||
seek(0, ::IO::SEEK_SET) | ||
end | ||
|
||
# Sets the file position to `new_position`. | ||
def pos=(new_position) | ||
seek(new_position, ::IO::SEEK_SET) | ||
end | ||
|
||
alias_method :pos, :tell | ||
|
||
# Checks if the stream is at the end of the file. | ||
def eof | ||
position = tell | ||
seek(0, ::IO::SEEK_END) | ||
tell == position | ||
end | ||
|
||
alias_method :eof?, :eof | ||
|
||
# Returns the total length of the stream. | ||
def length | ||
current_position = tell | ||
seek(0, ::IO::SEEK_END) | ||
tell.tap { self.pos = current_position } | ||
end | ||
|
||
alias_method :size, :length | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,5 @@ | |
# frozen_string_literal: true | ||
|
||
module OpenDAL | ||
VERSION = "0.1.9" | ||
VERSION = "0.1.10" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.