Created
October 4, 2019 02:41
-
-
Save harrisonmalone/59799e0e1215c015365e23552a714d15 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
| # what is a block? | |
| # [1,2,3].each { |number| p number } | |
| # what is yield? | |
| # def hello | |
| # name = "harrison" | |
| # yield(5) | |
| # puts name | |
| # end | |
| # result = hello do |number| | |
| # p number | |
| # end | |
| # p result | |
| class Array | |
| def my_each | |
| index = 0 | |
| while index < self.length | |
| # puts self[index] | |
| yield | |
| index += 1 | |
| end | |
| return self | |
| end | |
| end | |
| result = [1,2,3].my_each do | |
| puts "hello" | |
| end | |
| p result | |
| # 1. finish off my_each so that uts functionality is the same as .each | |
| # 2. make your own .map (call it my_map) | |
| # 3. make your own .select (call it my_select) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment