first_non_nil 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/first_non_nil.rb +8 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d1462874dc5caac732cd9926672686dc33a9cef9
4
+ data.tar.gz: 13f6581be04b44ca259fb2e07ff4ad2b209e3a9a
5
+ SHA512:
6
+ metadata.gz: 74ec5653bf706522a81003ccf51b0b1436f41d1b4c4d301f38d85314e9ebec4a4c70313131d5d032fd090f4be85cc4a8300e66b0ecf309a73e6405314a189038
7
+ data.tar.gz: 9e0460f70db3de766bbc88c8e94a9fe1217a3b1d35b50f32ab6185c603294a1da236faa2df94080af56709425aa6641bba992d3e72b0a44bb067f60b822fd9f2
@@ -0,0 +1,8 @@
1
+ class Array
2
+ def first_non_nil
3
+ self.each do |element|
4
+ result = block_given? ? yield(element) : element
5
+ return result unless result.nil?
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: first_non_nil
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Carlin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Return the first element of an array that is not nil or, if given a block,
14
+ the first non-nil result of the given block.
15
+ email: davich@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/first_non_nil.rb
21
+ homepage: https://github.com/davich/first_non_nil
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.6.8
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Return the first element that is not nil
45
+ test_files: []