Created
August 14, 2020 06:57
-
-
Save 3014zhangshuo/c7f895537cdd7f0d13e177f94ba76402 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class DataModel | |
include Enumerable | |
def initialize data | |
@data = data | |
end | |
def each | |
@data.each { |x| yield x } | |
end | |
end | |
data_model = DataModel.new [2,3,4] | |
p data_model.select { |x| x > 3 } | |
p data_model.any? { |x| x > 3 } | |
(1..Float::INFINITY).select { |x| x % 27 == 0 }.take(10) | |
(1..Float::INFINITY).lazy.select { |x| x % 27 == 0 }.take(10) | |
(1..Float::INFINITY).lazy.select { |x| x % 27 == 0 }.take(10).to_a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment