Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Created October 4, 2019 02:41
Show Gist options
  • Select an option

  • Save harrisonmalone/59799e0e1215c015365e23552a714d15 to your computer and use it in GitHub Desktop.

Select an option

Save harrisonmalone/59799e0e1215c015365e23552a714d15 to your computer and use it in GitHub Desktop.
# 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