anildigital (owner)

Fork Of

Revisions

gist: 132041 Download_button fork
public
Public Clone URL: git://gist.github.com/132041.git
Embed All Files: show embed
return.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
module Enumerable
  def return
    each do |i|
      value = yield(i)
      return value if value
    end
    nil
  end
end
 
h = {0 => 'a', 2 => 'b'}
[1,2,3].return {|x| h[x]} # => b
[4,5,6].return {|x| h[x]} # => nil