union 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (7) hide show
  1. data/CHANGES +7 -2
  2. data/README +30 -30
  3. data/lib/union.rb +47 -47
  4. data/test/test_union.rb +50 -50
  5. metadata +10 -14
  6. data/Rakefile +0 -22
  7. data/union.gemspec +0 -22
data/CHANGES CHANGED
@@ -1,2 +1,7 @@
1
- = 1.0.0 - 10-Jun-2008
2
- * Initial release
1
+ == 1.0.1 - 31-Jul-2009
2
+ * Now compatible with Ruby 1.9.x
3
+ * Changed the license to Artistic 2.0.
4
+ * Some gemspec updates, including the addition of a license.
5
+
6
+ == 1.0.0 - 10-Jun-2008
7
+ * Initial release
data/README CHANGED
@@ -1,31 +1,31 @@
1
- = Description
2
- A struct-like C union class for Ruby.
3
-
4
- = Installation
5
- rake test (optional)
6
- rake install (standard) or rake install_gem (rubygems)
7
-
8
- = Synopsis
9
- require 'union'
10
-
11
- Union.new('Human', :name, :age, :height)
12
- h = Union::Human.new
13
-
14
- # Only one attribute of the union may be set
15
- h.name = 'Daniel' # => #<struct Union::Human name="Daniel", age=nil>
16
- h.age = 38 # => #<struct Union::Human name=nil, age=38>
17
-
18
- = Known issues or bugs
19
- None that I'm aware of. Please report any bugs you find on the project page
20
- at http://www.rubyforge.org/projects/shards
21
-
22
- = License
23
- Ruby's
24
-
25
- = Warranty
26
- This package is provided "as is" and without any express or
27
- implied warranties, including, without limitation, the implied
28
- warranties of merchantability and fitness for a particular purpose.
29
-
30
- = Author
1
+ = Description
2
+ The union library is the Ruby analog of a C union.
3
+
4
+ = Installation
5
+ rake test (optional)
6
+ rake install (standard) or rake install_gem (rubygems)
7
+
8
+ = Synopsis
9
+ require 'union'
10
+
11
+ Union.new('Human', :name, :age, :height)
12
+ h = Union::Human.new
13
+
14
+ # Only one attribute of the union may be set
15
+ h.name = 'Daniel' # => #<struct Union::Human name="Daniel", age=nil>
16
+ h.age = 38 # => #<struct Union::Human name=nil, age=38>
17
+
18
+ = Known issues or bugs
19
+ None that I'm aware of. Please report any bugs you find on the project page
20
+ at http://www.rubyforge.org/projects/shards
21
+
22
+ = License
23
+ Artistic 2.0
24
+
25
+ = Warranty
26
+ This package is provided "as is" and without any express or
27
+ implied warranties, including, without limitation, the implied
28
+ warranties of merchantability and fitness for a particular purpose.
29
+
30
+ = Author
31
31
  * Daniel J. Berger
data/lib/union.rb CHANGED
@@ -1,47 +1,47 @@
1
- # The Union class mimics a C union, where only one member of a Union
2
- # object can be set to a non-nil value at a time.
3
- #
4
- class Union < Struct
5
- # The version of this library
6
- VERSION = '1.0.0'
7
-
8
- # Creates and returns a new Union. Unlike Struct::Class.new, this does not
9
- # take any arguments. You must assign attributes individually.
10
- #
11
- # Union.new('Human', :name, :age)
12
- # h = Union::Human.new
13
- #
14
- # h.name = 'Daniel' # => #<struct Union::Human name="Daniel", age=nil>
15
- # h.age = 38 # => #<struct Union::Human name=nil, age=38>
16
- #--
17
- # The semantics of Union.new(arg1, arg2, ...) would be non-sensical. Which
18
- # attribute should be set while the rest are ignored? The first one or the
19
- # last one? I decided to disallow it altogether.
20
- #
21
- def initialize
22
- super
23
- members.each{ |attribute|
24
- m = %Q{
25
- def #{attribute}=(value)
26
- self['#{attribute}'] = value
27
- end
28
- }
29
- instance_eval(m)
30
- }
31
- end
32
-
33
- # Identical to Struct attribute assignment, except that setting one instance
34
- # variable sets all other instance variables to nil. Also, you cannot use a
35
- # numeric index. You must use a string or symbol.
36
- #
37
- # Union.new('Human', :name, :age)
38
- # h = Union::Human.new
39
- #
40
- # h[:name] = 'Daniel' # => #<struct Union::Human name="Daniel", age=nil>
41
- # h[:age] = 38 # => #<struct Union::Human name=nil, age=38>
42
- #
43
- def []=(symbol, value)
44
- super(symbol, value)
45
- members.each{ |m| super(m, nil) unless m == symbol.to_s }
46
- end
47
- end
1
+ # The Union class provides an analogue of a C union. Only one member of
2
+ # a Union object can be set to a non-nil value at a time.
3
+ #
4
+ class Union < Struct
5
+ # The version of this library
6
+ VERSION = '1.0.1'
7
+
8
+ # Creates and returns a new Union. Unlike Struct::Class.new, this does not
9
+ # take any arguments. You must assign attributes individually.
10
+ #
11
+ # Union.new('Human', :name, :age)
12
+ # h = Union::Human.new
13
+ #
14
+ # h.name = 'Daniel' # => #<struct Union::Human name="Daniel", age=nil>
15
+ # h.age = 38 # => #<struct Union::Human name=nil, age=38>
16
+ #--
17
+ # The semantics of Union.new(arg1, arg2, ...) would be non-sensical. Which
18
+ # attribute should be set while the rest are ignored? The first one or the
19
+ # last one? I decided to disallow it altogether.
20
+ #
21
+ def initialize
22
+ super
23
+ members.each{ |attribute|
24
+ m = %Q{
25
+ def #{attribute}=(value)
26
+ self['#{attribute}'] = value
27
+ end
28
+ }
29
+ instance_eval(m)
30
+ }
31
+ end
32
+
33
+ # Identical to Struct attribute assignment, except that setting one instance
34
+ # variable sets all other instance variables to nil. Also, you cannot use a
35
+ # numeric index. You must use a string or symbol.
36
+ #
37
+ # Union.new('Human', :name, :age)
38
+ # h = Union::Human.new
39
+ #
40
+ # h[:name] = 'Daniel' # => #<struct Union::Human name="Daniel", age=nil>
41
+ # h[:age] = 38 # => #<struct Union::Human name=nil, age=38>
42
+ #
43
+ def []=(symbol, value)
44
+ super(symbol, value)
45
+ members.each{ |m| super(m, nil) unless m.to_s == symbol.to_s }
46
+ end
47
+ end
data/test/test_union.rb CHANGED
@@ -1,50 +1,50 @@
1
- require 'union'
2
- require 'test/unit'
3
-
4
- class TC_Union < Test::Unit::TestCase
5
- def setup
6
- Union.new('Human', :name, :age, :height) unless defined? Union::Human
7
- @union = Union::Human.new
8
- end
9
-
10
- def test_union_version
11
- assert_equal('1.0.0', Union::VERSION)
12
- end
13
-
14
- def test_union_constructor
15
- assert_raise(ArgumentError){ Union::Human.new('Matz') }
16
- end
17
-
18
- def test_union_attribute_assignment_basic
19
- assert_nothing_raised{ @union.name = 'Daniel' }
20
- assert_equal('Daniel', @union.name)
21
- end
22
-
23
- def test_union_attribute_assignment_by_method_name
24
- assert_nothing_raised{ @union.name = 'Daniel' }
25
- assert_nothing_raised{ @union.age = 38 }
26
- assert_nil(@union.name)
27
- assert_nil(@union.height)
28
- assert_equal(38, @union.age)
29
- end
30
-
31
- def test_union_attribute_assignment_by_string_ref
32
- assert_nothing_raised{ @union['name'] = 'Daniel' }
33
- assert_nothing_raised{ @union['age'] = 38 }
34
- assert_nil(@union['name'])
35
- assert_nil(@union['height'])
36
- assert_equal(38, @union['age'])
37
- end
38
-
39
- def test_union_attribute_assignment_by_symbol_ref
40
- assert_nothing_raised{ @union[:name] = 'Daniel' }
41
- assert_nothing_raised{ @union[:age] = 38 }
42
- assert_nil(@union[:name])
43
- assert_nil(@union[:height])
44
- assert_equal(38, @union[:age])
45
- end
46
-
47
- def teardown
48
- @union = nil
49
- end
50
- end
1
+ require 'union'
2
+ require 'test/unit'
3
+
4
+ class TC_Union < Test::Unit::TestCase
5
+ def setup
6
+ Union.new('Human', :name, :age, :height) unless defined? Union::Human
7
+ @union = Union::Human.new
8
+ end
9
+
10
+ def test_union_version
11
+ assert_equal('1.0.1', Union::VERSION)
12
+ end
13
+
14
+ def test_union_constructor
15
+ assert_raise(ArgumentError){ Union::Human.new('Matz') }
16
+ end
17
+
18
+ def test_union_attribute_assignment_basic
19
+ assert_nothing_raised{ @union.name = 'Daniel' }
20
+ assert_equal('Daniel', @union.name)
21
+ end
22
+
23
+ def test_union_attribute_assignment_by_method_name
24
+ assert_nothing_raised{ @union.name = 'Daniel' }
25
+ assert_nothing_raised{ @union.age = 38 }
26
+ assert_nil(@union.name)
27
+ assert_nil(@union.height)
28
+ assert_equal(38, @union.age)
29
+ end
30
+
31
+ def test_union_attribute_assignment_by_string_ref
32
+ assert_nothing_raised{ @union['name'] = 'Daniel' }
33
+ assert_nothing_raised{ @union['age'] = 38 }
34
+ assert_nil(@union['name'])
35
+ assert_nil(@union['height'])
36
+ assert_equal(38, @union['age'])
37
+ end
38
+
39
+ def test_union_attribute_assignment_by_symbol_ref
40
+ assert_nothing_raised{ @union[:name] = 'Daniel' }
41
+ assert_nothing_raised{ @union[:age] = 38 }
42
+ assert_nil(@union[:name])
43
+ assert_nil(@union[:height])
44
+ assert_equal(38, @union[:age])
45
+ end
46
+
47
+ def teardown
48
+ @union = nil
49
+ end
50
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: union
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-10 00:00:00 -06:00
12
+ date: 2009-07-31 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description:
16
+ description: " The union library provides an analog to a C/C++ union for Ruby.\n In this implementation a union is a kind of struct where multiple\n members may be defined, but only one member ever contains a non-nil\n value at any given time.\n"
17
17
  email: djberg96@gmail.com
18
18
  executables: []
19
19
 
@@ -25,18 +25,14 @@ extra_rdoc_files:
25
25
  - MANIFEST
26
26
  files:
27
27
  - lib/union.rb
28
+ - test/test_union.rb
29
+ - README
28
30
  - CHANGES
29
- - CVS
30
- - lib
31
31
  - MANIFEST
32
- - Rakefile
33
- - README
34
- - test
35
- - union.gemspec
36
- - test/CVS
37
- - test/test_union.rb
38
32
  has_rdoc: true
39
33
  homepage: http://www.rubyforge.org/projects/shards
34
+ licenses:
35
+ - Artistic 2.0
40
36
  post_install_message:
41
37
  rdoc_options: []
42
38
 
@@ -56,10 +52,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
52
  version:
57
53
  requirements: []
58
54
 
59
- rubyforge_project:
60
- rubygems_version: 1.1.1
55
+ rubyforge_project: shards
56
+ rubygems_version: 1.3.5
61
57
  signing_key:
62
- specification_version: 2
58
+ specification_version: 3
63
59
  summary: A struct-like C union for Ruby
64
60
  test_files:
65
61
  - test/test_union.rb
data/Rakefile DELETED
@@ -1,22 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rbconfig'
4
- include Config
5
-
6
- desc 'Install the union library (non-gem)'
7
- task :install do
8
- sitelibdir = CONFIG["sitelibdir"]
9
- file = "lib/union.rb"
10
- FileUtils.cp(file, sitelibdir, :verbose => true)
11
- end
12
-
13
- task :install_gem do
14
- ruby 'union.gemspec'
15
- file = Dir["*.gem"].first
16
- sh "gem install #{file}"
17
- end
18
-
19
- Rake::TestTask.new do |t|
20
- t.verbose = true
21
- t.warning = true
22
- end
data/union.gemspec DELETED
@@ -1,22 +0,0 @@
1
- require "rubygems"
2
-
3
- spec = Gem::Specification.new do |gem|
4
- gem.name = "union"
5
- gem.version = "1.0.0"
6
- gem.author = "Daniel J. Berger"
7
- gem.email = "djberg96@gmail.com"
8
- gem.homepage = "http://www.rubyforge.org/projects/shards"
9
- gem.platform = Gem::Platform::RUBY
10
- gem.summary = "A struct-like C union for Ruby"
11
- gem.test_file = "test/test_union.rb"
12
- gem.has_rdoc = true
13
- gem.files = Dir['lib/*.rb'] + Dir['[A-Z]*'] + Dir['test/*']
14
- gem.files.reject! { |fn| fn.include? "CVS" }
15
- gem.require_path = "lib"
16
- gem.extra_rdoc_files = ["README", "CHANGES", "MANIFEST"]
17
- end
18
-
19
- if $0 == __FILE__
20
- Gem.manage_gems
21
- Gem::Builder.new(spec).build
22
- end