values 1.1.0 → 1.2.0

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 (5) hide show
  1. data/README.md +2 -0
  2. data/VERSION +1 -1
  3. data/lib/values.rb +5 -3
  4. data/values.gemspec +1 -1
  5. metadata +3 -3
data/README.md CHANGED
@@ -27,3 +27,5 @@ Values fixes both of these:
27
27
  => NoMethodError: undefined method x= for #<Point:0x00000100943788 @x=0, @y=1>
28
28
  from (irb):6
29
29
  from /usr/local/bin/irb:12:in <main>
30
+
31
+ Value does NOT have all the features of Struct (nor is it meant to).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
data/lib/values.rb CHANGED
@@ -2,16 +2,18 @@ class Value
2
2
  def self.new(*fields)
3
3
  return Class.new do
4
4
  attr_reader *fields
5
+
5
6
  define_method(:initialize) do |*input_fields|
6
7
  raise ArgumentError.new("wrong number of arguments, #{input_fields.size} for #{fields.size}") if fields.size != input_fields.size
7
8
 
8
9
  fields.each_with_index do |field, index|
9
10
  instance_variable_set('@' + field.to_s, input_fields[index])
10
11
  end
11
- @__fields = fields
12
12
  self.freeze
13
13
  end
14
14
 
15
+ const_set :VALUE_ATTRS, fields
16
+
15
17
  def ==(other)
16
18
  self.eql?(other)
17
19
  end
@@ -19,7 +21,7 @@ class Value
19
21
  def eql?(other)
20
22
  return false if other.class != self.class
21
23
  result = true
22
- @__fields.each do |field|
24
+ self.class::VALUE_ATTRS.each do |field|
23
25
  result = result && self.send(field) == other.send(field)
24
26
  end
25
27
  return result
@@ -27,7 +29,7 @@ class Value
27
29
 
28
30
  def hash
29
31
  result = 0
30
- @__fields.each do |field|
32
+ self.class::VALUE_ATTRS.each do |field|
31
33
  result += field.hash
32
34
  end
33
35
  return result + self.class.hash
data/values.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{values}
8
- s.version = "1.1.0"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tom Crayford"]
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 1.1.0
9
+ version: 1.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tom Crayford
@@ -111,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
112
  - - ">="
113
113
  - !ruby/object:Gem::Version
114
- hash: 2901597111501063009
114
+ hash: -2915973544868875541
115
115
  segments:
116
116
  - 0
117
117
  version: "0"