enum 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/Changelog +0 -0
  2. data/LICENSE +0 -0
  3. data/README +0 -0
  4. data/init.rb +2 -0
  5. data/lib/enum.rb +47 -0
  6. data/test/foo.rb +11 -0
  7. metadata +72 -0
File without changes
data/LICENSE ADDED
File without changes
data/README ADDED
File without changes
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # Enum
2
+ require 'enum'
@@ -0,0 +1,47 @@
1
+ # Enum
2
+ class Enum
3
+ protected
4
+ def init *args
5
+ end
6
+ public
7
+ attr_reader :id, :name
8
+ def initialize *args
9
+ @id = args.shift
10
+ @name = args.shift
11
+ init *args
12
+ end
13
+ def to_sym;name;end
14
+ def to_s;name.to_s;end
15
+ def to_i;@id;end
16
+ def inspect;"#{self.class}::#{name}##{id}";end
17
+ def save;end
18
+ def save!;end
19
+ class << self
20
+ def values
21
+ @values ||= []
22
+ end
23
+ alias all values
24
+ def find id
25
+ values[id]
26
+ end
27
+ def each
28
+ values.each do |value|
29
+ yield value
30
+ end
31
+ end
32
+ protected
33
+ def missing *args
34
+ name = args.first
35
+ value = new(values.length,*args)
36
+ values.push value
37
+ const_set(name,value)
38
+ value
39
+ end
40
+ def method_missing *args
41
+ missing *args
42
+ end
43
+ def const_missing *args
44
+ missing *args
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,11 @@
1
+ require 'enum'
2
+
3
+ class Foo < Enum
4
+ FOO
5
+ BAR(1,2,3)
6
+ BLEEP
7
+ end
8
+
9
+ Foo::BUGGER(:off)
10
+
11
+ puts Foo.values.inspect
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enum
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - CapnRegex
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-10 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: " Java like enum functionality when you need more than a unique identifier. \n"
23
+ email: capnregex@gmail.org
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README
32
+ - Changelog
33
+ - LICENSE
34
+ - test/foo.rb
35
+ - init.rb
36
+ - lib/enum.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/capnregex/enum
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.7
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: java like enum functionality.
71
+ test_files: []
72
+