Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Kernel
- def enum(constant_names)
- Module.new do |mod|
- n = 0
- constant_names.each_with_index do |const, i|
- if constant_names[i + 1].to_i > 0
- n = constant_names[i + 1].to_i
- constant_names.delete_at(i + 1)
- end
- mod.const_set(const.to_s, n)
- n += 1
- end
- end
- end
- def add_enum(enum_ref, constant_names)
- n = enum_ref.constants.size
- constant_names.each_with_index do |const, i|
- if constant_names[i + 1].to_i > 0
- n = constant_names[i + 1].to_i
- constant_names.delete_at(i + 1)
- end
- enum_ref.const_set(const.to_s, n)
- n += 1
- end
- end
- end
- module Enums
- Param = enum %w(
- MAXHP
- MAXMP
- ATK
- DEF
- MAT
- MDF
- AGI
- LUK
- )
- end
- print Enums.constants
- puts
- print Enums.const_get(:Param).constants
- puts
- print Enums::Param::MAXHP
- puts
- module Enums
- add_enum(Param, %w(PER
- HRT
- CON))
- end
- print Enums.const_get(:Param).constants
- puts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement