Class::Enum

'Classial' class enum for Ruby
class Animal
include Class::Enum
attr_reader :sound
def initialize(sound)
@sound = sound
end
field :CAT, "meow"
field :DOG, "bark"
field :BIRD, "tweet"
end
puts Animal::CAT.sound
case Animal::CAT
when Animal
puts "An animal"
else
puts "X"
end
Animal::CAT.instance_of?(Animal)
Animal::CAT.class
Requirements
Usage
See documentation
Examples
Using block
class Animal
include Class::Enum
attr_reader :block
def initialize(&block)
@block = block
end
field :CAT do
puts "meow"
end
end
Animal::CAT.block.call
Using keyword arguments
You can keyword arguments only if ruby 2.0+.
If not ruby 2.0+, this gem doesn't use keyword arguments
class Animal
include Class::Enum
attr_reader :sound
def initialize(sound:)
@sound = sound
end
field :CAT, sound: "meow"
end
puts Animal::CAT.sound
Author
Sputnik Gugja (sputnikgugja@gmail.com)
License
This is free software released into the public domain (CC0 license).
See LICENSE
file.