equal_rights_for_hash 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.
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "equal_rights_for_hash"
4
- s.version = "0.0.2"
4
+ s.version = "0.0.3"
5
5
  s.authors = ["Suraj N. Kurapati"]
6
6
  s.email = ["sunaku@gmail.com"]
7
7
  s.homepage = "http://redmine.ruby-lang.org/issues/5008"
@@ -8,7 +8,7 @@ class Object
8
8
  def to_h
9
9
  if respond_to? :to_hash
10
10
  to_hash
11
- elsif respond_to? :to_ary and not all? {|item| item.respond_to? :to_ary }
11
+ elsif respond_to? :all? and not all? {|item| item.respond_to? :to_ary }
12
12
  Hash[*self]
13
13
  else
14
14
  Hash[self]
data/test/to_h_test.rb CHANGED
@@ -53,4 +53,14 @@ class TestToH < Test::Unit::TestCase
53
53
  assert_equal({}, [[1, 2, 3, 4]].to_h)
54
54
  assert_equal({}, [[1, 2, 3, 4, 5]].to_h) # and so on
55
55
  end
56
+
57
+ def test_works_on_enumerables
58
+ assert_equal({1 => 2, 3 => 4}, (1..4).to_a.to_h)
59
+ assert_equal({1 => 2, 3 => 4}, (1..4).to_h)
60
+ end
61
+
62
+ def test_works_on_enumerators
63
+ assert_equal({1 => 2, 3 => 4}, (1..4).to_enum.to_a.to_h)
64
+ assert_equal({1 => 2, 3 => 4}, (1..4).to_enum.to_h)
65
+ end
56
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: equal_rights_for_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: