類別 Fiddle::CStruct

用於表示 C 結構的物件的基底類別

公開類別方法

entity_class() 按一下以切換來源

存取器至 Fiddle::CStructEntity

# File ext/fiddle/lib/fiddle/struct.rb, line 12
def CStruct.entity_class
  CStructEntity
end

公開實例方法

each() { |self| ... } 按一下以切換來源
# File ext/fiddle/lib/fiddle/struct.rb, line 68
def each
  return enum_for(__function__) unless block_given?

  self.class.members.each do |name,|
    yield(self[name])
  end
end
each_pair() { |name, self| ... } 按一下以切換來源
# File ext/fiddle/lib/fiddle/struct.rb, line 76
def each_pair
  return enum_for(__function__) unless block_given?

  self.class.members.each do |name,|
    yield(name, self[name])
  end
end
replace(another) 按一下以切換來源
# File ext/fiddle/lib/fiddle/struct.rb, line 92
def replace(another)
  if another.nil?
    self.class.members.each do |name,|
      self[name] = nil
    end
  elsif another.respond_to?(:each_pair)
    another.each_pair do |name, value|
      self[name] = value
    end
  else
    another.each do |name, value|
      self[name] = value
    end
  end
  self
end
to_h() 按一下以切換來源
# File ext/fiddle/lib/fiddle/struct.rb, line 84
def to_h
  hash = {}
  each_pair do |name, value|
    hash[name] = unstruct(value)
  end
  hash
end

私人實例方法

unstruct(value) 按一下以切換來源
# File ext/fiddle/lib/fiddle/struct.rb, line 110
def unstruct(value)
  case value
  when CStruct
    value.to_h
  when Array
    value.collect do |v|
      unstruct(v)
    end
  else
    value
  end
end