Sha256: ca288d317705b3794f5db4469177f049082507bf278b85ed87c2c7f87b6eaecb

Contents?: true

Size: 736 Bytes

Versions: 7

Compression:

Stored size: 736 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

7 entries across 7 versions & 1 rubygems

Version Path
libtcod-0.0.9 lib/libtcod/struct.rb
libtcod-0.0.8 lib/libtcod/struct.rb
libtcod-0.0.7 lib/libtcod/struct.rb
libtcod-0.0.6 lib/libtcod/struct.rb
libtcod-0.0.5 lib/libtcod/struct.rb
libtcod-0.0.4 lib/libtcod/struct.rb
libtcod-0.0.3 lib/libtcod/struct.rb