simple_struct 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_struct.rb +12 -2
- metadata +3 -3
data/lib/simple_struct.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
class SimpleStruct
|
2
2
|
|
3
|
-
VERSION = "0.0.
|
3
|
+
VERSION = "0.0.4"
|
4
4
|
|
5
5
|
def self.new *members, &block
|
6
6
|
subclass = Class.new(self)
|
7
|
-
subclass.define_singleton_method(:new,
|
7
|
+
subclass.define_singleton_method(:new, Object.method(:new))
|
8
8
|
subclass.define_singleton_method(:members){ members }
|
9
9
|
subclass.class_eval(&block) if block_given?
|
10
10
|
subclass
|
@@ -35,6 +35,11 @@ eval <<-RUBY if $0 == __FILE__
|
|
35
35
|
|
36
36
|
require 'test/unit'
|
37
37
|
|
38
|
+
class ComplexStruct < SimpleStruct
|
39
|
+
end
|
40
|
+
|
41
|
+
class GrowAFlower < ComplexStruct.new(:type, :count)
|
42
|
+
end
|
38
43
|
|
39
44
|
class MethodObjectTestUnitTestCase < Test::Unit::TestCase
|
40
45
|
|
@@ -53,6 +58,11 @@ class MethodObjectTestUnitTestCase < Test::Unit::TestCase
|
|
53
58
|
assert car_instance.is_a?(SimpleStruct), "Car is not a SimpleStruct"
|
54
59
|
end
|
55
60
|
|
61
|
+
def test_SimpleStruct_Subclass
|
62
|
+
assert_equal GrowAFlower.inspect, "GrowAFlower(type, count)"
|
63
|
+
assert_equal GrowAFlower.new(:rose, 12).inspect, "#<GrowAFlower: type=:rose, count=12>"
|
64
|
+
end
|
65
|
+
|
56
66
|
end
|
57
67
|
|
58
68
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -39,7 +39,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
39
|
version: '0'
|
40
40
|
segments:
|
41
41
|
- 0
|
42
|
-
hash:
|
42
|
+
hash: 3964948240972837749
|
43
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
44
|
none: false
|
45
45
|
requirements:
|
@@ -48,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
48
|
version: '0'
|
49
49
|
segments:
|
50
50
|
- 0
|
51
|
-
hash:
|
51
|
+
hash: 3964948240972837749
|
52
52
|
requirements: []
|
53
53
|
rubyforge_project:
|
54
54
|
rubygems_version: 1.8.24
|