epitools 0.5.105 → 0.5.106

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d427d1b5d8c2314e24298cf32b86887e9f4592c3
4
- data.tar.gz: 7e4ba5fbe4bdb2b3f07484f63f53fec7dba23389
3
+ metadata.gz: e62d7058f8223acc7bf84eb7c77fc32e78c94735
4
+ data.tar.gz: c9b8d58d8dd39c12e78ccf29aeacc5a0c109edfc
5
5
  SHA512:
6
- metadata.gz: 56cfdcaf9cc2b1d56e41a0eacad29c004cdf675f996a4281074f714dee52435c5dcd062b61d7ba0f32930b10044d7cbfb318670eea8b1a6a6d8f970953fdcd61
7
- data.tar.gz: 442b4209f5caf2d85b3a90980d15e4a7114d2521eda593e8f641c29674617e5f6914f33a445c014dd35887fb3c88193d336b3f9c4327c50e3dd648b84864db5b
6
+ metadata.gz: 89a89b7b72de4c1c71f46af1a2b27e2dc02811d82034c8e17cd84a36e44c0a14fb28ead350509f150b3ec6f258175d2a3714a5f9455409a84924735a659cf794
7
+ data.tar.gz: 4962e60b4daf5eb39c623d606a04bc08846e24aae70f2e003028c96c2f4f6a76874d030adfb8972079bbd485de06d4bf2afac931e1fdbfe3d3b70113ed1f93d7
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.105
1
+ 0.5.106
@@ -111,7 +111,7 @@ class File
111
111
  seek(-(data.size - index), IO::SEEK_CUR)
112
112
  break
113
113
  elsif eof?
114
- break
114
+ return nil
115
115
  else
116
116
  seek(-(string.size - 1), IO::SEEK_CUR)
117
117
  end
@@ -133,7 +133,7 @@ class File
133
133
  seek(index+string.size, IO::SEEK_CUR)
134
134
  break
135
135
  elsif pos == 0
136
- break
136
+ return nil
137
137
  else
138
138
  seek(string.size - 1, IO::SEEK_CUR)
139
139
  end
@@ -257,6 +257,19 @@ module ObjectSpace
257
257
 
258
258
  end
259
259
 
260
+
261
+ #
262
+ # Make OpenStruct a little tiny bit more like a Hash
263
+ #
264
+ class OpenStruct
265
+ def empty?; @table ? @table.empty? : true; end
266
+ def blank?; empty?; end
267
+ def any?; !empty?; end
268
+
269
+ def keys; @table&.keys || []; end
270
+ end
271
+
272
+
260
273
  #
261
274
  # Flush standard input's buffer.
262
275
  #
@@ -428,7 +428,7 @@ class String
428
428
  #
429
429
  # String#to_proc
430
430
  #
431
- # See http://weblog.raganwald.com/2007/10/stringtoproc.html
431
+ # See: http://weblog.raganwald.com/2007/10/stringtoproc.html
432
432
  #
433
433
  # Ported from the String Lambdas in Oliver Steele's Functional Javascript
434
434
  # http://osteele.com/sources/javascript/functional/
@@ -438,6 +438,105 @@ class String
438
438
  # (c) 2007 Reginald Braithwaite
439
439
  # Portions Copyright (c) 2006 Oliver Steele
440
440
  #
441
+ #
442
+ # ## Basic Usage
443
+ #
444
+ # 'x+1'.to_proc[2];
445
+ # → 3
446
+ # 'x+2*y'.to_proc[2, 3];
447
+ # → 8
448
+ # or (more usefully) later:
449
+ #
450
+ # square = 'x*x'.to_proc;
451
+ # square(3);
452
+ # → 9
453
+ # square(4);
454
+ # → 16
455
+ #
456
+ # ## Explicit parameters
457
+ #
458
+ # If the string contains a ->, this separates the parameters from the body.
459
+ #
460
+ # 'x y -> x+2*y'.to_proc[2, 3];
461
+ # → 8
462
+ # 'y x -> x+2*y'.to_proc[2, 3];
463
+ # → 7
464
+ # Otherwise, if the string contains a _, it’s a unary function and _ is name of the parameter:
465
+ #
466
+ # '_+1'.to_proc[2];
467
+ # → 3
468
+ # '_*_'.to_proc[3];
469
+ # → 9
470
+ # ## Implicit parameters
471
+ #
472
+ # If the string doesn’t specify explicit parameters, they are implicit.
473
+ #
474
+ # If the string starts with an operator or relation besides -, or ends with an operator or relation, then its implicit arguments are placed at the beginning and/or end:
475
+ #
476
+ # '*2'.to_proc[2];
477
+ # → 4
478
+ # '/2'.to_proc[4];
479
+ # → 2
480
+ # '2/'.to_proc[4];
481
+ # → 0.5
482
+ # '/'.to_proc[2, 4];
483
+ # → 0.5
484
+ # ’.’ counts as a right operator:
485
+ #
486
+ # '.abs'.to_proc[-1];
487
+ # → 1
488
+ #
489
+ #
490
+ # Otherwise, the variables in the string, in order of occurrence, are its parameters.
491
+ #
492
+ # 'x+1'.to_proc[2];
493
+ # → 3
494
+ # 'x*x'.to_proc[3];
495
+ # → 9
496
+ # 'x + 2*y'.to_proc[1, 2];
497
+ # → 5
498
+ # 'y + 2*x'.to_proc[1, 2];
499
+ # → 5
500
+ #
501
+ # ## Chaining
502
+ #
503
+ # Chain -> to create curried functions.
504
+ #
505
+ # 'x y -> x+y'.to_proc[2, 3];
506
+ # → 5
507
+ # 'x -> y -> x+y'.to_proc[2][3];
508
+ # → 5
509
+ # plus_two = 'x -> y -> x+y'.to_proc[2];
510
+ # plus_two[3]
511
+ # → 5
512
+ #
513
+ # Using String#to_proc in Idiomatic Ruby
514
+ #
515
+ # Ruby on Rails popularized Symbol#to_proc, so much so that it will be part of Ruby 1.9.
516
+ #
517
+ # If you like:
518
+ #
519
+ # %w[dsf fgdg fg].map(&:capitalize)
520
+ # → ["Dsf", "Fgdg", "Fg"]
521
+ # then %w[dsf fgdg fg].map(&'.capitalize') isn’t much of an improvement.
522
+ #
523
+ # But what about doubling every value in a list:
524
+ #
525
+ # (1..5).map &'*2'
526
+ # → [2, 4, 6, 8, 10]
527
+ #
528
+ # Or folding a list:
529
+ #
530
+ # (1..5).inject &'+'
531
+ # → 15
532
+ #
533
+ # Or having fun with factorial:
534
+ #
535
+ # factorial = "(1.._).inject &'*'".to_proc
536
+ # factorial[5]
537
+ # → 120
538
+ #
539
+ # LICENSE:
441
540
  # Permission is hereby granted, free of charge, to any person obtaining
442
541
  # a copy of this software and associated documentation files (the
443
542
  # "Software"), to deal in the Software without restriction, including
@@ -108,6 +108,8 @@ require 'epitools/core_ext/string'
108
108
  #
109
109
  class Path
110
110
 
111
+ include Enumerable
112
+
111
113
  # The directories in the path, split into an array. (eg: ['usr', 'src', 'linux'])
112
114
  attr_reader :dirs
113
115
 
@@ -637,10 +639,11 @@ class Path
637
639
  #
638
640
  # All the lines in this file, chomped.
639
641
  #
640
- def each_line
642
+ def each
641
643
  io.each_line
642
644
  end
643
- alias_method :lines, :each_line
645
+ alias_method :each_line, :each
646
+ alias_method :lines, :each
644
647
 
645
648
  def grep(pat)
646
649
  return to_enum(:grep, pat).to_a unless block_given?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.105
4
+ version: 0.5.106
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-08 00:00:00.000000000 Z
11
+ date: 2017-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec