Class: Ole::IOMode

### Home Classes Methods

### In Files

- lib/ole/support.rb

### Parent

Object

### Namespace

- MODULE Ole::IOMode::Constants

### Methods

- ::new
- ::parse_mode
- #append?
- #binary?
- #create?
- #inspect
- #readable?
- #truncate?
- #writeable?

### Included Modules

- Ole::IOMode::Constants

### Files

- ChangeLog
- README

### Class/Module Index

Quicksearch

- Ole
- Ole::IOMode
- Ole::IOMode::Constants
- Ole::Storage
- Ole::Storage::AllocationTable
- Ole::Storage::AllocationTable::Big
- Ole::Storage::AllocationTable::Small
- Ole::Storage::DirClass
- Ole::Storage::DirClass::Dir
- Ole::Storage::Dirent
- Ole::Storage::FileClass
- Ole::Storage::FileClass::Stat
- Ole::Storage::Header
- Ole::Storage::MetaData
- Ole::Storage::RangesIOMigrateable
- Ole::Storage::RangesIOResizeable
- Ole::Types
- Ole::Types::Clsid
- Ole::Types::Data
- Ole::Types::FileTime
- Ole::Types::Lpstr
- Ole::Types::Lpwstr
- Ole::Types::PropertySet
- Ole::Types::PropertySet::Constants
- Ole::Types::PropertySet::Section
- Ole::Types::Variant
- Ole::Types::Variant::Constants
- RangesIO

No matching classes.

# 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.