Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing exercise solutions #3

Open
dmitrymar opened this issue Jul 18, 2020 · 1 comment
Open

Missing exercise solutions #3

dmitrymar opened this issue Jul 18, 2020 · 1 comment

Comments

@dmitrymar
Copy link

dmitrymar commented Jul 18, 2020

It would be great to have exercise solutions. In my case I wanted to verify if my solution to the exercise on page 189 (chapter 6) is correct.
Here is my attempt...

class Array
  def my_each
    c = 0
    until c == size
      yield self[c]
      c += 1
    end
    self
  end
end

class Integer
  def my_times
    c = 0
    acc = []
    until c == self
      acc << c
      c += 1
    end
    acc.my_each { |e| yield e }
    self
  end
end

5.my_times { |i| puts "I'm on iteration #{i}!" }

@ChrisKey13
Copy link

You should maybe give it a god and PR your solution. It works satisfyingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants