module Obfusk::Util::BetterStruct

better Struct; create using Obfusk::Util.struct

Public Class Methods

included(base) click to toggle source

include class methods as well

# File lib/obfusk/util/struct.rb, line 23
def self.included(base)
  base.extend ClassMethods
end

Public Instance Methods

check!() click to toggle source

checks for missing fields, returns self @raise IncompleteError if any fields are nil

# File lib/obfusk/util/struct.rb, line 39
def check!
  members.each do |f|
    self[f].nil? and raise IncompleteError, "empty field: #{f}"
  end; self
end
to_h() click to toggle source

convert to hash (ruby 2 has this already)

# File lib/obfusk/util/struct.rb, line 52
def to_h
  Hash[each_pair.to_a]
end
to_str_h() click to toggle source

convert to hash w/ string keys

# File lib/obfusk/util/struct.rb, line 58
def to_str_h
  Hash[to_h.map { |k,v| [k.to_s,v] }]
end