Skip to content

Instantly share code, notes, and snippets.

@aileron
Created November 13, 2014 02:42
Show Gist options
  • Save aileron/7ad7dffa54a22072de7e to your computer and use it in GitHub Desktop.
Save aileron/7ad7dffa54a22072de7e to your computer and use it in GitHub Desktop.
class Array
def eql_all? &block
block = lambda {|a|a} unless block
max=self.length
i=0
c = block.( self[i] )
n = nil
result = while i+1<max
n=block.(self[i+1])
break false unless c == n
c=n
i+=1
end
result.nil?
end
end
@gogotanaka
Copy link

なるほど、であれば

class Array
  def eql_all?(&block)
    map(&block).uniq.count == 1
  end
end

で良いかもしれませんね、uniqは===比較してくれる気がするので.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment