Module: SDL2::EnumUtil

Included in:
SDL2, Image
Defined in:
lib/sdl2.rb

Instance Method Summary collapse

Instance Method Details

#enum_consts(*args) ⇒ Object

enum_consts convenient like FFI’s enum but creates the symbols as normal consts which I believe is more natural to ruby



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sdl2.rb', line 10

def enum_consts *args
 pname = nil
 value = 1

 args.each do |arg|

  if arg.is_a? Symbol
   if pname
    #puts "const_set #{pname} = #{value}"
    const_set(pname, value)
    pname = nil
    value += 1
   end
   pname = arg

  elsif arg.is_a? Integer
   if pname
    value = arg
    #puts "const_set #{pname} = #{value}"
    const_set(pname, value)
    pname = nil
    value += 1
   else
    raise "unexpected integer without preceeding name"
   end
  end

 end # do

 if pname
  #puts "const_set #{pname} = #{value}"
  const_set(pname, value)
 end

end