KQueue::Native::Flags

A module containing all the C-level integer flags that are used with kqueue.

@private

Public Class Methods

from_flag(prefix, flag) click to toggle source

Converts an integer from the C API into a flag.

@param prefix [String] The prefix for the C names of the flags @param flag [Fixnum] @return [Symbol]

# File lib/rb-kqueue/native/flags.rb, line 106
def self.from_flag(prefix, flag)
  re = /^#{Regexp.quote prefix}_/
  constants.each do |sym|
    c = sym.to_s
    next unless c =~ re
    return c.to_s.sub("#{prefix}_", "").downcase.to_sym if const_get(c) == flag
  end
end
from_mask(prefix, mask) click to toggle source

Converts a bitmask from the C API into a list of flags.

@param prefix [String] The prefix for the C names of the flags @param mask [Fixnum] @return [Array<Symbol>]

# File lib/rb-kqueue/native/flags.rb, line 83
def self.from_mask(prefix, mask)
  re = /^#{Regexp.quote prefix}_/
  constants.select do |sym|
    c = sym.to_s
    next false unless c =~ re
    const_get(c) & mask != 0
  end.map {|c| c.to_s.sub("#{prefix}_", "").downcase.to_sym}
end
to_flag(prefix, flag) click to toggle source

Converts a flag to the integer that the C API expects.

@param prefix [String] The prefix for the C names of the flags @param flag [Symbol] @return [Fixnum]

# File lib/rb-kqueue/native/flags.rb, line 97
def self.to_flag(prefix, flag)
  const_get("#{prefix}_#{flag.to_s.upcase}")
end
to_mask(prefix, flags) click to toggle source

Converts a list of flags to the bitmask that the C API expects.

@param prefix [String] The prefix for the C names of the flags @param flags [Array<Symbol>] @return [Fixnum]

# File lib/rb-kqueue/native/flags.rb, line 73
def self.to_mask(prefix, flags)
  flags.map {|flag| const_get("#{prefix}_#{flag.to_s.upcase}")}.
    inject(0) {|mask, flag| mask | flag}
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.