object-let 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in object-let.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ronen Barzel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = object-let
2
+
3
+ Defines Object#let, which simply yields the object and returns the result.
4
+ This idiom, familiar to Lisp programmers, can be handy to eliminate the need
5
+ for an intermediate variable when you need to use the result of a
6
+ computation multiple times.
7
+
8
+ For example, without +let+, you might write:
9
+
10
+ biggest = my_things.find_biggest
11
+ bounds = Bound.new(:width => biggest.width, :height => biggest.height)
12
+
13
+ with +let+, this could be:
14
+
15
+ bounds = my_things.find_biggest.let { |biggest|
16
+ Bound.new(:width => biggest.width, :height => biggest.height)
17
+ }
18
+
19
+
20
+ Stylistically, as well in terms of lexical scoping (for ruby 1.9), this
21
+ idiom can make clear that the intermediate result is of no importance outside the
22
+ block.
23
+
24
+ = See also
25
+
26
+ Discussion at http://www.opensourcery.com/blog/zack-hobson/objectlet-ruby-0
27
+
28
+ Alternative implementation at http://ick.rubyforge.org/inside.html
29
+
30
+ The "let" gem (https://rubygems.org/gems/let) provides a module that can be
31
+ included in a class to define memoizing accessors. That gem and this one
32
+ are compatible.
33
+
34
+
35
+ == Installation
36
+
37
+ Install via:
38
+
39
+ % gem install object-let
40
+
41
+ or in your Gemfile:
42
+
43
+ gem "object-let"
44
+
45
+ == Copyright
46
+
47
+ Released under the MIT License. See LICENSE for details.
48
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.rspec_opts = '-Ispec'
7
+ end
@@ -0,0 +1,7 @@
1
+ module ObjectLet
2
+ module Object
3
+ def let
4
+ yield self
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module ObjectLet
2
+ VERSION = "0.0.1"
3
+ end
data/lib/object-let.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "object-let/version"
2
+ require "object-let/object"
3
+
4
+ Object.send :include, ObjectLet::Object
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/object-let/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["ronen barzel"]
6
+ gem.email = ["ronen@barzel.org"]
7
+ gem.description = %q{Defines Object#let, which yields the object and returns the result}
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
+ gem.homepage = 'http://github.com/ronen/object-let'
10
+ gem.extra_rdoc_files = [
11
+ 'LICENSE',
12
+ 'README.rdoc',
13
+ ]
14
+
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.files = `git ls-files`.split("\n")
17
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ gem.name = "object-let"
19
+ gem.require_paths = ["lib"]
20
+ gem.version = ObjectLet::VERSION
21
+
22
+ gem.add_development_dependency 'rspec'
23
+ gem.add_development_dependency 'simplecov'
24
+ gem.add_development_dependency 'simplecov-gem-adapter'
25
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe "Object" do
4
+
5
+ it "should support let method" do
6
+ obj = Object.new
7
+ obj.should be_respond_to :let
8
+ end
9
+
10
+ it "let should yield the object" do
11
+ obj = Object.new
12
+ obj.let { |arg|
13
+ arg.should equal obj
14
+ }
15
+ end
16
+
17
+ it "let should return the block result" do
18
+ obj = Object.new
19
+ obj.let{|arg| 3}.should == 3
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ if RUBY_VERSION > "1.9"
2
+ require 'simplecov'
3
+ require 'simplecov-gem-adapter'
4
+ SimpleCov.start 'gem'
5
+ end
6
+
7
+ require 'rspec'
8
+ require 'object-let'
9
+
10
+ # Requires supporting files with custom matchers and macros, etc,
11
+ # in ./support/ and its subdirectories.
12
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
13
+
14
+ RSpec.configure do |config|
15
+
16
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: object-let
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - ronen barzel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70124170808020 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70124170808020
25
+ - !ruby/object:Gem::Dependency
26
+ name: simplecov
27
+ requirement: &70124170806780 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70124170806780
36
+ - !ruby/object:Gem::Dependency
37
+ name: simplecov-gem-adapter
38
+ requirement: &70124170805840 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70124170805840
47
+ description: Defines Object#let, which yields the object and returns the result
48
+ email:
49
+ - ronen@barzel.org
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.rdoc
55
+ files:
56
+ - .gitignore
57
+ - Gemfile
58
+ - LICENSE
59
+ - README.rdoc
60
+ - Rakefile
61
+ - lib/object-let.rb
62
+ - lib/object-let/object.rb
63
+ - lib/object-let/version.rb
64
+ - object-let.gemspec
65
+ - spec/object_spec.rb
66
+ - spec/spec_helper.rb
67
+ homepage: http://github.com/ronen/object-let
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.10
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Defines Object#let, which yields the object and returns the result. This
91
+ idiom can be handy to eliminate the need for an intermediate variable when you need
92
+ to use the result of a computation multiple times.
93
+ test_files:
94
+ - spec/object_spec.rb
95
+ - spec/spec_helper.rb