rubyhacks 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -492,6 +492,11 @@ class Array
492
492
  def sum
493
493
  return inject{|old, new| old + new}
494
494
  end
495
+
496
+ def mean
497
+ return sum/size.to_f
498
+ end
499
+
495
500
  def product
496
501
  return inject{|old, new| old * new}
497
502
  end
@@ -625,12 +630,12 @@ class FloatHash < Hash
625
630
  end
626
631
  aliold :pretty_inspect
627
632
  def pretty_inspect
628
- "FloatHash.from_hash(#{old_pretty_inspect})"
629
- end
633
+ "FloatHash.from_hash(#{old_pretty_inspect})"
634
+ end
630
635
 
631
636
  def []=(key, var)
632
637
  # super(key.to_f, var)
633
- # raise TypeError unless key.kind
638
+ raise TypeError unless key.kind_of? Numeric
634
639
  old_key = self.find{|k, v| (k-key.to_f).abs < Float::EPSILON}
635
640
  if old_key
636
641
  super(old_key[0].to_f, var)
@@ -642,9 +647,11 @@ class FloatHash < Hash
642
647
  def [](key)
643
648
  # # # super(key.to_f)
644
649
  # raise TypeError unless key.class == Float
645
- old_key = self.find{|k, v| (k-key.to_f).abs < Float::EPSILON}
650
+ #old_key = self.find{|k, v| (k-key.to_f).abs < Float::EPSILON}
651
+ raise TypeError unless key.kind_of? Numeric
652
+ old_key = self.keys.inject{|o, n| ((o-key).abs < (n-key).abs) ? o : n }
646
653
  if old_key
647
- return super(old_key[0])
654
+ return super(old_key)
648
655
  else
649
656
  return nil
650
657
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rubyhacks"
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Edmund Highcock"]
12
- s.date = "2012-10-09"
12
+ s.date = "2013-08-15"
13
13
  s.description = "A collection of handy little hacks to Ruby objects. Does not modify default behaviours."
14
14
  s.email = "edmundhighcock@sourceforge.net"
15
15
  s.extra_rdoc_files = [
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
33
33
  s.homepage = "http://github.com/edmundhighcock/rubyhacks"
34
34
  s.licenses = ["MIT"]
35
35
  s.require_paths = ["lib"]
36
- s.rubygems_version = "1.8.24"
36
+ s.rubygems_version = "1.8.23"
37
37
  s.summary = "A collection of handy little hacks to Ruby objects."
38
38
 
39
39
  if s.respond_to? :specification_version then
@@ -1,7 +1,12 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestRubyhacks < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
4
+ def test_float_hash
5
+ fh = FloatHash.new
6
+ fh[0.4325] = 0.2342437
7
+ fh[0.4232432] = 0.232443
8
+ assert_equal(0.2342437, fh[0.433])
9
+ assert_equal(0.2342437, fh[5.0])
10
+ assert_raise(TypeError){fh['bb'] = 55}
11
+ end
7
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyhacks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-09 00:00:00.000000000 Z
12
+ date: 2013-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shoulda
@@ -111,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  segments:
113
113
  - 0
114
- hash: -2741353701333184386
114
+ hash: 2841264561825389949
115
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 1.8.24
123
+ rubygems_version: 1.8.23
124
124
  signing_key:
125
125
  specification_version: 3
126
126
  summary: A collection of handy little hacks to Ruby objects.