diff --git a/lib/rodash.rb b/lib/rodash.rb index e95ed09..f83d26a 100644 --- a/lib/rodash.rb +++ b/lib/rodash.rb @@ -164,7 +164,7 @@ def self.isKey(value, object) return true if value.is_a? Numeric return !value.is_a?(Array) && (@@reIsPlainProp =~ value || !@@reIsDeepProp =~ value || - (!object.nil? && object.has_key?(value))) + (!object.nil? && !object.is_a?(Array) && object.has_key?(value))) end def self.baseToPath(value) diff --git a/test/test_rodash.rb b/test/test_rodash.rb index 8a0ab5a..00ebb3f 100644 --- a/test/test_rodash.rb +++ b/test/test_rodash.rb @@ -141,6 +141,13 @@ class GetTest < Test::Unit::TestCase end end + should "get a key from an array" do + object = {'a' => 1}, {'a' => 2} + + assert_equal Rodash.get(object, '[0].a'), 1 + assert_equal Rodash.get(object, '[1].a'), 2 + end + should "no coerce array paths to strings" do object = {'a,b,c' => 3, 'a' => { 'b' => { 'c' => 4 } } } assert_equal Rodash.get(object, ['a', 'b', 'c']), 4