mozart 0.0.2 → 0.0.3
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.
- data/lib/mozart/value.rb +6 -1
- data/lib/mozart/version.rb +1 -1
- data/test/value_test.rb +11 -0
- metadata +1 -1
data/lib/mozart/value.rb
CHANGED
@@ -15,6 +15,10 @@ module Mozart
|
|
15
15
|
self.class == other.class && __data__ == other.__data__
|
16
16
|
end
|
17
17
|
|
18
|
+
def to_hash
|
19
|
+
Marshal.load(Marshal.dump(__data__))
|
20
|
+
end
|
21
|
+
|
18
22
|
alias_method :eql?, :==
|
19
23
|
|
20
24
|
def hash
|
@@ -22,7 +26,8 @@ module Mozart
|
|
22
26
|
end
|
23
27
|
|
24
28
|
field_names.each do |name|
|
25
|
-
define_method(name)
|
29
|
+
define_method(name) { __data__[name] }
|
30
|
+
define_method("#{name}=") { |value| __data__[name] = value }
|
26
31
|
end
|
27
32
|
|
28
33
|
protected
|
data/lib/mozart/version.rb
CHANGED
data/test/value_test.rb
CHANGED
@@ -8,6 +8,17 @@ describe "Mozart.value" do
|
|
8
8
|
pos1 = pos_builder.new(:x => 10, :y => 20)
|
9
9
|
pos1.x.must_equal(10)
|
10
10
|
pos1.y.must_equal(20)
|
11
|
+
|
12
|
+
pos1.x = 20
|
13
|
+
pos1.x.must_equal(20)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "can be converted into a Hash object" do
|
17
|
+
pos_builder = Mozart.value(:x, :y)
|
18
|
+
|
19
|
+
pos1 = pos_builder.new(:x => 10, :y => 20)
|
20
|
+
|
21
|
+
pos1.to_hash.must_equal(:x => 10, :y => 20)
|
11
22
|
end
|
12
23
|
|
13
24
|
it "implements equality" do
|