Code Monkey home page Code Monkey logo

enuma's Introduction

Enuma

Description

Enuma is a small Ruby library to add enum semantics to an object.

Features

An attempt has been made to collect the best bits from other Ruby enum implementations.

Examples

require 'enuma'

Requirements

Install

$ gem install enuma

Credits

(list of other enum impls)

Copyright

Copyright (c) 2013 Don Morrison

See {file:LICENSE.txt} for details.

enuma's People

Contributors

elskwid avatar

Watchers

 avatar  avatar

enuma's Issues

Features from binarylogic/enumlogic

For consideration from binarylogic/enumlogic

https://github.com/binarylogic/enumlogic

  • class method for definition (enum)
  • _options method that returns hash for rails forms
  • .valid? method to validate inclusion of the enum field in an AR model
  • namespace option to namespace the methods with the field name
  • boolean query methods to test enum

examples:

Computer.enum :kind, ["apple", "dell", "hp"], :namespace => true
Computer.enum :kind, ["apple", "dell", "hp"]
Computer.enum :kind, {"apple" => "Apple", "dell" => "Dell", "hp" => "HP"}

Features from ddl1st/light_enum

For consideration from light_enum

https://github.com/ddl1st/light_enum

  • constant to access enums
  • constant to access enum values array
  • simple nested array syntax for declaration
  • query methods like foo.status_0?
  • accessor like foo.status_name

This one doesn't have much that I've considered before, putting it here for completeness.

example:

class Bar
  include ActiveModel::Validations
  include LightEnum
  attr_accessor :status,:published
  light_enum :status, ["Open","Close","Reopen",["Done","D"]],:validate => true
  light_enum :published,[["公开",1],["私人",2]]
end

Features from sholden/enum

For consideration from sholden/enum

https://github.com/sholden/enum

  • lookup by symbol or number
  • same subscript [square bracket] lookup for symbol or number
  • #valid? to test for key existence
  • #only method to return only values asked for
  • #except method to return all but the values stipulated
  • bitflag support - use bitwise operations

examples:

BitflagEnum.new(:global, :group, :user)
Enum.new(:jake, :finn, :princess_bubblegum, :peppermint_butler)

Features from toplex/enum

For consideration from yinum (enum)

https://github.com/toplex/enum

  • simple instance of an enumerator where name and values are parameters
  • dot notation for values
  • subscript (square bracket) notation for retrieving values
  • retrieve multiple values using subscript [1,4]
  • comparison of value to enum name
  • attr_enum syntax for adding to a class

too many examples: see README

Features from raphaelr/nice_enum

For consideration from nice_enum

https://github.com/raphaelr/nice_enum

  • enums are instances of the enclosing class
  • enumeration classes pass messages to underlying value
  • auto values: if you leave of the value of the enum it is created as a sequential integer
  • mix and match auto and explicit values
  • iteration
  • mix in enumerable
  • arbitrary value attributes (hash)
  • default attribute values
  • add methods to enums (like struct style)

example:

class Number < Enum
  enum :Zero, 0, :squared => 0
  enum :One, 1, :note => "Average number of eyes per eyehole", :squared => 1
  enum :Five, 5, :note => "Number of digits per hand", :squared => 25
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.