binary_search
binary_search copied to clipboard
Docs out of date? Undefined method Array#binary_search
Following the readme:
$ gem install binary_search
Fetching: binary_search-0.3.0.gem (100%)
Building native extensions. This could take a while...
Successfully installed binary_search-0.3.0
1 gem installed
$ irb
1.9.3-p327 :001 > require 'binary_search/native'
=> true
1.9.3-p327 :002 > x = [5,1,6,7,2,6,4,2,6,1,6,1,1,8,3,5,2].sort
=> [1, 1, 1, 1, 2, 2, 2, 3, 4, 5, 5, 6, 6, 6, 6, 7, 8]
1.9.3-p327 :004 > target = 4
=> 4
1.9.3-p327 :005 > y = [[1,:a], [2,:b], [3,:c], [4,:d]]
=> [[1, :a], [2, :b], [3, :c], [4, :d]]
1.9.3-p327 :006 > puts x.binary_search { |v| target <=> v[0] }
NoMethodError: undefined method `binary_search' for [1, 1, 1, 1, 2, 2, 2, 3, 4, 5, 5, 6, 6, 6, 6, 7, 8]:Array
from (irb):6
from /home/gabe2/.rvm/rubies/ruby-1.9.3-p327/bin/irb:13:in `<main>'
Same problem here. Using Mac OS.
It works for me... Also using OS X.
It seems the native version does not define this method.