object-let 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d0d8bb1b58d8659a345743a265b42557cf002f8
4
+ data.tar.gz: a9864dfddc18e11a6c098c1925784fe23efcdced
5
+ SHA512:
6
+ metadata.gz: 1133a8aa2c47074c937c7c24022ea332f77b159437db3a5b8b42d87f73468066dc8f56f0f26d3f1b0d1d5ca814b5407c243d8cc159fce774fc63d116ecf74d92
7
+ data.tar.gz: 8f4fbf51509869a5c79fc55a293d28e19043b717f07568e49e37b3ff8880c38c84f623357cb4978bcfb2ab4b3cd8e5e78c37f0bc6db5c9059235cf3a44f861f8
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.9
4
+ - 2.2.5
5
+ - 2.3.1
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # object-let
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/object-let.svg)](https://badge.fury.io/rb/object-let)
4
+ [![Build Status](https://secure.travis-ci.org/ronen/object-let.png)](http://travis-ci.org/ronen/object-let)
5
+ [![Dependency Status](https://gemnasium.com/ronen/object-let.png)](https://gemnasium.com/ronen/object-let)
6
+
7
+
8
+ Defines `Object#let`, which simply yields the object and returns the result.
9
+ This idiom, familiar to Lisp programmers, can be handy to eliminate the need
10
+ for an intermediate variable when you need to use the result of a computation
11
+ multiple times, or at the tail of a method chain.
12
+
13
+ For example, without `let`, you might write:
14
+
15
+ ```ruby
16
+ biggest = my_things.find_biggest
17
+ bounds = Bound.new(:width => biggest.width, :height => biggest.height)
18
+ ```
19
+
20
+ with `let`, this could be:
21
+
22
+ ```ruby
23
+ bounds = my_things.find_biggest.let { |biggest|
24
+ Bound.new(:width => biggest.width, :height => biggest.height)
25
+ }
26
+ ```
27
+
28
+ Stylistically, as well in terms of lexical scoping, this idiom
29
+ can make clear that the intermediate result is of no importance outside the
30
+ block.
31
+
32
+ You can also think of this as analogous to "map" in a method chain, but for a
33
+ single value rather than for an enumerable. Compare:
34
+
35
+ ```ruby
36
+ array_of_items = thingy.item_names.map { |name| Item.new(:name => name) }
37
+ just_one_item = thingy.item_name.let { |name| Item.new(:name => name) }
38
+ ```
39
+
40
+ # See also
41
+
42
+ Alternative implementation at http://ick.rubyforge.org/inside.html
43
+
44
+ The "let" gem (https://rubygems.org/gems/let) provides a module that can be
45
+ included in a class to define memoizing accessors. That gem and this one are
46
+ compatible.
47
+
48
+ ## Installation
49
+
50
+ Install via:
51
+
52
+ % gem install object-let
53
+
54
+ or in your Gemfile:
55
+
56
+ gem "object-let"
57
+
58
+ ## Compatibility
59
+
60
+ The gem is tested on ruby 2.1.9, 2.2.5, and 2.3.1
61
+
62
+ ## History
63
+
64
+ * 1.0.0 - remove `Object#let_if`; on ruby >= 2.3 using `&.let` is cleaner and nearly equivalent (differ only in falsey vs nil). Drop support for ruby <= 1.9
65
+
66
+ * 0.1.0 - Add `Object#let_if`
67
+
68
+ * 0.0.1 - Initial version
69
+
70
+ ## Copyright
71
+
72
+ Released under the MIT License. See LICENSE for details.
73
+
74
+
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
3
 
4
+ task :default => :spec
5
+
4
6
  require 'rspec/core/rake_task'
5
7
  RSpec::Core::RakeTask.new(:spec) do |spec|
6
8
  spec.rspec_opts = '-Ispec'
@@ -3,8 +3,5 @@ module ObjectLet
3
3
  def let
4
4
  yield self
5
5
  end
6
- def let_if
7
- yield self if self
8
- end
9
6
  end
10
7
  end
@@ -1,3 +1,3 @@
1
1
  module ObjectLet
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/object-let.gemspec CHANGED
@@ -7,11 +7,6 @@ Gem::Specification.new do |gem|
7
7
  gem.description = %q{Defines Object#let, which yields the object and returns the result}
8
8
  gem.summary = %q{Defines Object#let, which yields the object and returns the result. This idiom can be handy to eliminate the need for an intermediate variable when you need to use the result of a computation multiple times.}
9
9
  gem.homepage = 'http://github.com/ronen/object-let'
10
- gem.extra_rdoc_files = [
11
- 'LICENSE',
12
- 'README.rdoc',
13
- ]
14
-
15
10
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
11
  gem.files = `git ls-files`.split("\n")
17
12
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -19,7 +14,8 @@ Gem::Specification.new do |gem|
19
14
  gem.require_paths = ["lib"]
20
15
  gem.version = ObjectLet::VERSION
21
16
 
22
- gem.add_development_dependency 'rspec'
23
- gem.add_development_dependency 'simplecov'
24
- gem.add_development_dependency 'simplecov-gem-adapter'
17
+ gem.add_development_dependency 'rake'
18
+ gem.add_development_dependency 'rspec', "~> 3.0"
19
+ gem.add_development_dependency 'simplecov', "~> 0.12"
20
+ gem.add_development_dependency 'simplecov-gem-profile'
25
21
  end
data/spec/object_spec.rb CHANGED
@@ -1,58 +1,17 @@
1
1
  require "spec_helper"
2
2
 
3
- shared_examples "let" do
4
-
5
- it "should be supported" do
6
- obj = Object.new
7
- obj.should be_respond_to method
8
- end
3
+ describe "Object" do
9
4
 
10
- it "should yield the object" do
5
+ it "yields the object" do
11
6
  obj = Object.new
12
- obj.send(method) { |arg|
13
- arg.should equal obj
7
+ obj.let { |arg|
8
+ expect(arg).to eq obj
14
9
  }
15
10
  end
16
11
 
17
- it "should return the block result" do
12
+ it "returns the block result" do
18
13
  obj = Object.new
19
- obj.send(method) {|arg| 3}.should == 3
20
- end
21
- end
22
-
23
- shared_examples "let_if" do
24
- it "should not yield" do
25
- expect { subject.let_if { raise "in block"} }.should_not raise_error
26
- end
27
-
28
- it "should return nil" do
29
- subject.let_if { 12345 }.should be_nil
30
- end
31
- end
32
-
33
- describe "Object" do
34
-
35
- context "let" do
36
- it_should_behave_like "let" do
37
- let(:method) { :let }
38
- end
39
- end
40
-
41
- context "let_if" do
42
- it_should_behave_like "let" do
43
- let(:method) { :let_if }
44
- end
45
-
46
- context "when object is nil" do
47
- subject { nil }
48
- it_should_behave_like "let_if"
49
- end
50
-
51
- context "when object is false" do
52
- subject { false }
53
- it_should_behave_like "let_if"
54
- end
55
-
14
+ expect(obj.let {|arg| 3}).to eq 3
56
15
  end
57
16
 
58
17
  end
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,6 @@
1
- if RUBY_VERSION > "1.9"
2
- require 'simplecov'
3
- require 'simplecov-gem-adapter'
4
- SimpleCov.start 'gem'
5
- end
1
+ require 'simplecov'
2
+ require 'simplecov-gem-profile'
3
+ SimpleCov.start 'gem'
6
4
 
7
5
  require 'rspec'
8
6
  require 'object-let'
metadata CHANGED
@@ -1,62 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object-let
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - ronen barzel
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-06-04 00:00:00.000000000 Z
11
+ date: 2016-07-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: rspec
16
- requirement: &70259253506940 !ruby/object:Gem::Requirement
17
- none: false
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *70259253506940
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
25
41
  - !ruby/object:Gem::Dependency
26
42
  name: simplecov
27
- requirement: &70259253506520 !ruby/object:Gem::Requirement
28
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
29
44
  requirements:
30
- - - ! '>='
45
+ - - "~>"
31
46
  - !ruby/object:Gem::Version
32
- version: '0'
47
+ version: '0.12'
33
48
  type: :development
34
49
  prerelease: false
35
- version_requirements: *70259253506520
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.12'
36
55
  - !ruby/object:Gem::Dependency
37
- name: simplecov-gem-adapter
38
- requirement: &70259253506060 !ruby/object:Gem::Requirement
39
- none: false
56
+ name: simplecov-gem-profile
57
+ requirement: !ruby/object:Gem::Requirement
40
58
  requirements:
41
- - - ! '>='
59
+ - - ">="
42
60
  - !ruby/object:Gem::Version
43
61
  version: '0'
44
62
  type: :development
45
63
  prerelease: false
46
- version_requirements: *70259253506060
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
47
69
  description: Defines Object#let, which yields the object and returns the result
48
70
  email:
49
71
  - ronen@barzel.org
50
72
  executables: []
51
73
  extensions: []
52
- extra_rdoc_files:
53
- - LICENSE
54
- - README.rdoc
74
+ extra_rdoc_files: []
55
75
  files:
56
- - .gitignore
76
+ - ".gitignore"
77
+ - ".travis.yml"
57
78
  - Gemfile
58
79
  - LICENSE
59
- - README.rdoc
80
+ - README.md
60
81
  - Rakefile
61
82
  - lib/object-let.rb
62
83
  - lib/object-let/object.rb
@@ -66,31 +87,29 @@ files:
66
87
  - spec/spec_helper.rb
67
88
  homepage: http://github.com/ronen/object-let
68
89
  licenses: []
90
+ metadata: {}
69
91
  post_install_message:
70
92
  rdoc_options: []
71
93
  require_paths:
72
94
  - lib
73
95
  required_ruby_version: !ruby/object:Gem::Requirement
74
- none: false
75
96
  requirements:
76
- - - ! '>='
97
+ - - ">="
77
98
  - !ruby/object:Gem::Version
78
99
  version: '0'
79
100
  required_rubygems_version: !ruby/object:Gem::Requirement
80
- none: false
81
101
  requirements:
82
- - - ! '>='
102
+ - - ">="
83
103
  - !ruby/object:Gem::Version
84
104
  version: '0'
85
105
  requirements: []
86
106
  rubyforge_project:
87
- rubygems_version: 1.8.10
107
+ rubygems_version: 2.5.1
88
108
  signing_key:
89
- specification_version: 3
109
+ specification_version: 4
90
110
  summary: Defines Object#let, which yields the object and returns the result. This
91
111
  idiom can be handy to eliminate the need for an intermediate variable when you need
92
112
  to use the result of a computation multiple times.
93
113
  test_files:
94
114
  - spec/object_spec.rb
95
115
  - spec/spec_helper.rb
96
- has_rdoc:
data/README.rdoc DELETED
@@ -1,71 +0,0 @@
1
- = object-let
2
-
3
- {<img src="https://gemnasium.com/ronen/object-let.png" alt="Dependency Status" />}[https://gemnasium.com/ronen/object-let]
4
-
5
- Defines <tt>Object#let</tt>, which simply yields the object and returns the result.
6
- This idiom, familiar to Lisp programmers, can be handy to eliminate the need
7
- for an intermediate variable when you need to use the result of a
8
- computation multiple times.
9
-
10
- For example, without +let+, you might write:
11
-
12
- biggest = my_things.find_biggest
13
- bounds = Bound.new(:width => biggest.width, :height => biggest.height)
14
-
15
- with +let+, this could be:
16
-
17
- bounds = my_things.find_biggest.let { |biggest|
18
- Bound.new(:width => biggest.width, :height => biggest.height)
19
- }
20
-
21
-
22
- Stylistically, as well in terms of lexical scoping (for ruby 1.9), this
23
- idiom can make clear that the intermediate result is of no importance outside the
24
- block.
25
-
26
- You can also think of this as analogous to "map" in a method chain, but for a single value
27
- rather than for an enumerable. Compare:
28
-
29
- array_of_items = thingy.item_names.map{ |name| Item.new(:name => name) }
30
- just_one_item = thingy.item_name.let { |name| Item.new(:name => name) }
31
-
32
-
33
- <tt>Object#let_if</tt> behaves like <tt>Object#let</tt> except that it only yields if the
34
- object is truthy; otherwise it returns nil. So, modifying the above
35
- example:
36
-
37
- bounds = my_things.find_biggest.let_if { |biggest|
38
- Bound.new(:width => biggest.width, :height => biggest.height)
39
- }
40
-
41
- +bounds+ will be nil if +find_biggest+ returns nil.
42
-
43
- = See also
44
-
45
- Discussion at http://www.opensourcery.com/blog/zack-hobson/objectlet-ruby-0
46
-
47
- Alternative implementation at http://ick.rubyforge.org/inside.html
48
-
49
- The "let" gem (https://rubygems.org/gems/let) provides a module that can be
50
- included in a class to define memoizing accessors. That gem and this one
51
- are compatible.
52
-
53
- == Installation
54
-
55
- Install via:
56
-
57
- % gem install object-let
58
-
59
- or in your Gemfile:
60
-
61
- gem "object-let"
62
-
63
- == History
64
-
65
- * 0.1.0 - Add <tt>Object#left_if</tt>
66
- * 0.0.1 - Initial version
67
-
68
- == Copyright
69
-
70
- Released under the MIT License. See LICENSE for details.
71
-