New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

class-enum

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

class-enum

  • 0.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Class::Enum

Gem Version

'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 # meow

case Animal::CAT
when Animal
	puts "An animal"
else
	puts "X"
end
# An animal

Animal::CAT.instance_of?(Animal) # => true
Animal::CAT.class # => Animal

Requirements

  • No

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 # meow

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 # meow

Author

Sputnik Gugja (sputnikgugja@gmail.com)

License

This is free software released into the public domain (CC0 license).

See LICENSE file.

FAQs

Package last updated on 04 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc