Skip to content

Instantly share code, notes, and snippets.

@ajtran303
Created May 8, 2020 17:24
Show Gist options
  • Save ajtran303/e69eedb5a16474e4a38927ebb3c6b11c to your computer and use it in GitHub Desktop.
Save ajtran303/e69eedb5a16474e4a38927ebb3c6b11c to your computer and use it in GitHub Desktop.
Iterate over array without #each
```ruby
n_arr = [1, 2, 3]
#=> [1, 2, 3]
def p_each(arr)
arr.size.times do |i|
p arr[i] * 2
end
arr
end
# p to console 2, 4, 6
p_each(n_arr)
#=> retval [1, 2, 3]
n_arr
#=> [1, 2, 3]
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment