module ByteObject

The ByteObject module adds several attribute methods to any class that includes it, to aid in writing programs that require manipulating bytes of specific size. It also has helper methods to make working with binary files easier.

Public Class Methods

included(base) click to toggle source

@!visibility private

# File lib/ByteObject.rb, line 7
def self.included(base)
  base.extend ByteAttributes
end

Public Instance Methods

from_hash!(hash) click to toggle source

Takes a hash (or hash-like object whose each method yields a key-value pair) and assigns the values of its keys to instance variables with the same names. If there is an attribute writer method, it will attempt to use that; otherwise it will set the instance variable directly (much to the chagrin of whoever wrote the official Ruby documentation).

As the bang might suggest, this method is dangerous and modifies the calling object. @param hash

# File lib/ByteObject.rb, line 83
def from_hash!(hash)
  hash.each do |key, value|
    if methods.include?("#{key}=".to_sym)
      send("#{key}=", value)
    else
      instance_variable_set("@#{key}", value)
    end
  end
end