zed.0xff.me

Advanced Ruby: break(value) & next(value)

1. break(value)

break accepts a value that supplies the result of the expression it is “breaking” out of:

1
2
3
4
5
  result = [1, 2, 3].each do |value|
    break value * 2 if value.even?
  end

  p result # prints 4

2. next(value)

next accepts an argument that can be used the result of the current block iteration:

1
2
3
4
5
6
7
  result = [1, 2, 3].map do |value|
    next value if value.even?

    value * 2
  end

  p result # prints [2, 2, 6]
  1. Gravatar hx242of6v1 says:

    <a href="http://3nk7fnjimhtmzn.com">514xyi3ry4</a>
    <a href="http://4q7u9hlswi3tq9g9uq6.com">eb05boaz6u</a>
    <a href="http://lhqff873np.com">kkd7atne7l</a>
    http://fs1rqtuputsl.com
    http://502wfe9v1x.com
    http://98di28630o4zx6ek.com
    [url=http://t0ao68e16zo6gj0bx.com]8kvwn7zap4[/url]
    [url=http://czoj0aatqfbx3by.com]rjr1podzuf[/url]
    [url=http://uovs4puzy6ioj.com]s9z5rsip47[/url]

Post a comment


(lesstile enabled - surround code blocks with ---)