Class: IO::Mode
Defined Under Namespace
Modules: Constants
Constant Summary collapse
- NAMES =
%w[rdonly wronly rdwr creat trunc append binary]
Constants included from Constants
Instance Attribute Summary collapse
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
Instance Method Summary collapse
- #append? ⇒ Boolean
- #binary? ⇒ Boolean
- #create? ⇒ Boolean
-
#initialize(flags) ⇒ Mode
constructor
A new instance of Mode.
-
#inspect ⇒ Object
# revisit this def apply io if truncate? io.truncate 0 elsif append? io.seek IO::SEEK_END, 0 end end.
- #readable? ⇒ Boolean
- #truncate? ⇒ Boolean
- #writeable? ⇒ Boolean
Constructor Details
#initialize(flags) ⇒ Mode
Returns a new instance of Mode.
207 208 209 210 211 |
# File 'lib/ole/support.rb', line 207 def initialize flags flags = IO.parse_mode flags.to_str if flags.respond_to? :to_str raise ArgumentError, "invalid flags - #{flags.inspect}" unless Fixnum === flags @flags = flags end |
Instance Attribute Details
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
206 207 208 |
# File 'lib/ole/support.rb', line 206 def flags @flags end |
Instance Method Details
#append? ⇒ Boolean
226 227 228 |
# File 'lib/ole/support.rb', line 226 def append? (@flags & APPEND) != 0 end |
#binary? ⇒ Boolean
234 235 236 |
# File 'lib/ole/support.rb', line 234 def binary? (@flags & BINARY) != 0 end |
#create? ⇒ Boolean
230 231 232 |
# File 'lib/ole/support.rb', line 230 def create? (@flags & CREAT) != 0 end |
#inspect ⇒ Object
# revisit this def apply io if truncate? io.truncate 0 elsif append? io.seek IO::SEEK_END, 0 end end
249 250 251 252 253 |
# File 'lib/ole/support.rb', line 249 def inspect names = NAMES.map { |name| name if (flags & Mode.const_get(name.upcase)) != 0 } names.unshift 'rdonly' if (flags & 0x3) == 0 "#<#{self.class} #{names.compact * '|'}>" end |
#readable? ⇒ Boolean
218 219 220 |
# File 'lib/ole/support.rb', line 218 def readable? (@flags & WRONLY) == 0 end |
#truncate? ⇒ Boolean
222 223 224 |
# File 'lib/ole/support.rb', line 222 def truncate? (@flags & TRUNC) != 0 end |
#writeable? ⇒ Boolean
213 214 215 216 |
# File 'lib/ole/support.rb', line 213 def writeable? #(@flags & RDONLY) == 0 (@flags & 0x3) != RDONLY end |