equal_rights_for_hash 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.1"
4
+ s.version = "0.0.2"
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,9 +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|
12
- item.respond_to? :to_ary and item.size <= 2 }
13
- then
11
+ elsif respond_to? :to_ary and not all? {|item| item.respond_to? :to_ary }
14
12
  Hash[*self]
15
13
  else
16
14
  Hash[self]
data/test/to_h_test.rb CHANGED
@@ -41,4 +41,16 @@ class TestToH < Test::Unit::TestCase
41
41
  def test_converts_nested_odd_array_into_hash
42
42
  assert_equal({1 => 2, 3 => nil}, [[1, 2], [3]].to_h)
43
43
  end
44
+
45
+ def test_converts_nested_array_with_one_or_two_items
46
+ assert_equal({1 => nil}, [[1]].to_h)
47
+ assert_equal({1 => 2}, [[1, 2]].to_h)
48
+ end
49
+
50
+ def test_ignores_nested_array_without_one_or_two_items
51
+ assert_equal({}, [[]].to_h) # zero items
52
+ assert_equal({}, [[1, 2, 3]].to_h)
53
+ assert_equal({}, [[1, 2, 3, 4]].to_h)
54
+ assert_equal({}, [[1, 2, 3, 4, 5]].to_h) # and so on
55
+ end
44
56
  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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: