object_as 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +11 -0
- data/lib/object_as/version.rb +3 -0
- data/lib/object_as.rb +20 -0
- data/lib/object_as_no_refinements.rb +18 -0
- data/object_as.gemspec +23 -0
- data/test/test_object_as.rb +10 -0
- data/test/test_object_as_no_refinement.rb +8 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f3e347ce7c24a0e05b63e4511275e005f4a3bbc
|
4
|
+
data.tar.gz: 9636725de1751fab9b7176cdb9abde1a584d6c3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a0c37f75b48450ae6ca8d15a2fbe97530840f9779dda9946c6b9e69a59f847b79da7ad38873172e3ca2aa3f7c5f9e83be1414d98c1d7b51caf59d25c2af5cc5b
|
7
|
+
data.tar.gz: ee78c6a3280f37c8dccb3d420ae30b656e21aac7a45bca8f21aaef5f72c3d3db58203df0af3acaca55faf59bf9367939ffa902c70b123765830ca25f3d3112c2
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Tallak Tveide
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# ObjectAs
|
2
|
+
|
3
|
+
A simple refinement to get Object#as
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'object_as'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install object_as
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Object#as it much like Object#tap except that it returns the value of the block
|
25
|
+
instead of the value being tapped.
|
26
|
+
|
27
|
+
> "Ruby".as {|n| n.reverse }
|
28
|
+
=> "ybuR"
|
29
|
+
|
30
|
+
Object#as is useful when chaining methods. This is a complete Ruby source file:
|
31
|
+
|
32
|
+
require 'object_as'
|
33
|
+
using ObjectAs
|
34
|
+
[1, 2, 3].map {|x| x * x }.as {|array| array.reverse }.each {|x| puts x }
|
35
|
+
# prints 9, 4 and 1
|
36
|
+
|
37
|
+
For Ruby versions older than 2.1, there is a way to use Object#as without
|
38
|
+
refinements. This method uses monkeypatching.
|
39
|
+
|
40
|
+
require 'object_as_no_refinements'
|
41
|
+
[1, 2, 3].map {|x| x * x }.as {|array| array.reverse }.each {|x| puts x }
|
42
|
+
# prints 9, 4 and 1
|
43
|
+
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it ( https://github.com/tallakt/object_as/fork )
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create a new Pull Request
|
52
|
+
|
data/Rakefile
ADDED
data/lib/object_as.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module ObjectAs
|
2
|
+
refine Object do
|
3
|
+
#
|
4
|
+
# call-seq:
|
5
|
+
# obj.as{|x|...} -> obj
|
6
|
+
#
|
7
|
+
# Yields self to the block, and then returns the return value of the block.
|
8
|
+
# The primary purpose of this method is to transform a value in a method
|
9
|
+
# chain without breaking the chain.
|
10
|
+
#
|
11
|
+
# [1, 2, 3]
|
12
|
+
# .map {|x| x * x }
|
13
|
+
# .as {|array| array.reverse }
|
14
|
+
# .each {|x| puts x }
|
15
|
+
#
|
16
|
+
def as
|
17
|
+
yield self
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Object
|
2
|
+
#
|
3
|
+
# call-seq:
|
4
|
+
# obj.as{|x|...} -> obj
|
5
|
+
#
|
6
|
+
# Yields self to the block, and then returns the return value of the block.
|
7
|
+
# The primary purpose of this method is to transform a value in a method
|
8
|
+
# chain without breaking the chain.
|
9
|
+
#
|
10
|
+
# [1, 2, 3]
|
11
|
+
# .map {|x| x * x }
|
12
|
+
# .as {|array| array.reverse }
|
13
|
+
# .each {|x| puts x }
|
14
|
+
#
|
15
|
+
def as
|
16
|
+
yield self
|
17
|
+
end
|
18
|
+
end
|
data/object_as.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'object_as/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "object_as"
|
8
|
+
spec.version = ObjectAs::VERSION
|
9
|
+
spec.authors = ["Tallak Tveide"]
|
10
|
+
spec.email = ["tallak@tveide.net"]
|
11
|
+
spec.summary = %q{Implementation of the Object#as method}
|
12
|
+
spec.description = %q{Object#as is useful for method chaining}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: object_as
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tallak Tveide
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Object#as is useful for method chaining
|
42
|
+
email:
|
43
|
+
- tallak@tveide.net
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/object_as.rb
|
54
|
+
- lib/object_as/version.rb
|
55
|
+
- lib/object_as_no_refinements.rb
|
56
|
+
- object_as.gemspec
|
57
|
+
- test/test_object_as.rb
|
58
|
+
- test/test_object_as_no_refinement.rb
|
59
|
+
homepage: ''
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.4.1
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Implementation of the Object#as method
|
83
|
+
test_files:
|
84
|
+
- test/test_object_as.rb
|
85
|
+
- test/test_object_as_no_refinement.rb
|