Sha256: 756c98af32c026e925be40faa4456383106ba9394e12aed82404d072503e3028

Contents?: true

Size: 702 Bytes

Versions: 3

Compression:

Stored size: 702 Bytes

Contents

module TCOD
  # Wrapper for FFI::Struct which allows access of
  # properties by method as well as indexing.

  class MethodStruct < FFI::Struct
    class << self
      alias_method :old_layout, :layout

      def layout(*keys)
        old_layout(*keys)
        keys.each_slice(2).each do |key,type|
          define_method(key) do
            self[key]
          end
        end
      end
    end
  end

  class MethodUnion < FFI::Union
    class << self
      alias_method :old_layout, :layout

      def layout(*keys)
        old_layout(*keys)
        keys.each_slice(2).each do |key,type|
          define_method(key) do
            self[key]
          end
        end
      end
    end
  end
end 

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
libtcod-0.1.1 lib/libtcod/struct.rb
libtcod-0.1.0 lib/libtcod/struct.rb
libtcod-0.0.2 lib/libtcod/struct.rb