Last active
April 11, 2016 17:48
-
-
Save groteck/4056270eddf90baa9280db04bd994f09 to your computer and use it in GitHub Desktop.
Blocks with "do" are different to Blocks with "{}"
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
#!/usr/bin/env ruby | |
puts "Count with {}" | |
puts [[1,1],[2],[3],[4,3]].count { |elements| !elements.all? { |element| element == elements.first } or elements.size == 1 } | |
puts "----------------------" | |
# Response: | |
# Count with {} | |
# 3 | |
# ---------------------- | |
puts "Count with do" | |
puts [[1,1],[2],[3],[4,3]].count do |elements| | |
!elements.all? { |element| element == elements.first } or elements.size == 1 | |
end | |
puts "----------------------" | |
# Response: | |
# Count with do | |
# 4 | |
# ---------------------- | |
puts "Map with {}" | |
puts [[1,1],[2],[3],[4,3]].map { |elements| !elements.all? { |element| element == elements.first } or elements.size == 1 } | |
puts "----------------------" | |
# Response: | |
# Map with {} | |
# false | |
# true | |
# true | |
# true | |
# ---------------------- | |
puts "Map with do" | |
puts [[1,1],[2],[3],[4,3]].map do |elements| | |
!elements.all? { |element| element == elements.first } or elements.size == 1 | |
end | |
puts "----------------------" | |
# Response: | |
# Map with do | |
# #<Enumerator:0x00000001dd68b8> | |
# ---------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment