Created
September 18, 2015 05:27
-
-
Save gamov/96e7c36beababe48719a to your computer and use it in GitHub Desktop.
Default value for an implicit block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def assert_sorted array, &block | |
block ||= lambda {|i,j| i+1 < j+1} | |
assert array.each_cons(2).all?(&block), 'Result data not correctly sorted' | |
end | |
assert_sorted [1,3,5] {|i,j| i+1 < j+1} #works | |
assert_sorted [1,3,5] #triggers: | |
ArgumentError: wrong number of arguments (1 for 2) | |
ruby.rb:2:in `block in assert_sorted' | |
ruby.rb:3:in `each' | |
ruby.rb:3:in `each_cons' | |
ruby.rb:3:in `each' | |
ruby.rb:3:in `all?' | |
ruby.rb:3:in `assert_sorted' | |
ruby.rb:7:in `test_scopes' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment