Parent

Namespace

Included Modules

Ole::IOMode

Constants

NAMES

Attributes

flags[R]

Public Class Methods

new(flags) click to toggle source
# File lib/ole/support.rb, line 198
def initialize flags
  flags = self.class.parse_mode flags.to_str if flags.respond_to? :to_str
  raise ArgumentError, "invalid flags - #{flags.inspect}" unless Fixnum === flags
  @flags = flags
end
parse_mode(mode) click to toggle source

nabbed from rubinius, and modified

# File lib/ole/support.rb, line 176
def self.parse_mode mode
  ret = 0

  case mode[0, 1]
  when 'r'; ret |= RDONLY
  when 'w'; ret |= WRONLY | CREAT | TRUNC
  when 'a'; ret |= WRONLY | CREAT | APPEND
  else raise ArgumentError, "illegal access mode #{mode}"
  end

  (1...mode.length).each do |i|
    case mode[i, 1]
    when '+'; ret = (ret & ~(RDONLY | WRONLY)) | RDWR
    when 'b'; ret |= BINARY
    else raise ArgumentError, "illegal access mode #{mode}"
    end
  end

  ret
end

Public Instance Methods

append?() click to toggle source
# File lib/ole/support.rb, line 217
def append?
  (@flags & APPEND) != 0
end
binary?() click to toggle source
# File lib/ole/support.rb, line 225
def binary?
  (@flags & BINARY) != 0
end
create?() click to toggle source
# File lib/ole/support.rb, line 221
def create?
  (@flags & CREAT) != 0
end
inspect() click to toggle source

# revisit this def apply io

if truncate?
  io.truncate 0
elsif append?
  io.seek IO::SEEK_END, 0
end

end

# File lib/ole/support.rb, line 240
def inspect
  names = NAMES.map { |name| name if (flags & IOMode.const_get(name.upcase)) != 0 }
  names.unshift 'rdonly' if (flags & 0x3) == 0
  "#<#{self.class} #{names.compact * '|'}>"
end
readable?() click to toggle source
# File lib/ole/support.rb, line 209
def readable?
  (@flags & WRONLY) == 0
end
truncate?() click to toggle source
# File lib/ole/support.rb, line 213
def truncate?
  (@flags & TRUNC) != 0
end
writeable?() click to toggle source
# File lib/ole/support.rb, line 204
def writeable?
  #(@flags & RDONLY) == 0
  (@flags & 0x3) != RDONLY
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.