with_else 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README +26 -0
  3. data/lib/with_else.rb +16 -0
  4. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 86eabd661510bd7cec83bef2d5768570e6029bee
4
+ data.tar.gz: 9e5070c5072afdd08ceb6d55639d85a94678fe48
5
+ SHA512:
6
+ metadata.gz: f320ab3f72b64937e083a9fdf86024e7e7a0e5ac9d6f066037f32650bf42aacd2108ca6cef3eaf07e164963894e5845d27f5ae7dabda6b5039826462f98cb6de
7
+ data.tar.gz: f2199d53cc0918d630470a5ba438b2a110165aed6b8fc7bfed943c98a3cb21d1235498b7c2cfc5a281c2aa6f573c8de2acc29ceadcfa74d8f80994b6b26e4998
data/README ADDED
@@ -0,0 +1,26 @@
1
+  
2
+ require 'with_else'
3
+
4
+ f = proc {puts "not breaking!"}
5
+
6
+ ar = 5.times.with_object([]) {|_, i| i << rand(5)}
7
+ ar.each.with_else(f) do |i|
8
+ puts i
9
+ break if i == 4
10
+ end
11
+  
12
+ require 'with_else'
13
+
14
+ class String
15
+ def not_include?(st)
16
+ f = proc {self}
17
+ l = st.size
18
+ (size - l + 1).times.with_else(f) do |i|
19
+ break false if self[i, l] == st
20
+ end
21
+ end
22
+ end
23
+
24
+ p "mijbdtoloov".not_include?("Ruby")
25
+ p "nice Ruby!".not_include?("Ruby")
26
+  
@@ -0,0 +1,16 @@
1
+ class Enumerator
2
+ def with_else(f, *args)
3
+ if block_given?
4
+ each {|*i| yield(*i)}
5
+ f.call(*args)
6
+ else
7
+ Enumerator.new do |y|
8
+ each do |*i|
9
+ a = (i.size <= 1) ? i[0] : i
10
+ y << a
11
+ end
12
+ f.call(*args)
13
+ end
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: with_else
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - obelisk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Python's 'for else' in Enumerator
14
+ email: obelisk_1968@mail.goo.ne.jp
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README
20
+ - lib/with_else.rb
21
+ homepage: http://obelisk.hatenablog.com/entry/2017/09/09/103457
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.5.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Python's 'for else'
45
+ test_files: []