backport_yield_self 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Manifest.txt +3 -0
- data/README.md +64 -0
- data/Rakefile +19 -0
- data/ext/backport_yield_self/backport_yield_self.c +58 -0
- data/ext/backport_yield_self/extconf.rb +42 -0
- data/lib/backport_yield_self.rb +1 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e7fedf2e485f54c376443518889f331a635e0734
|
4
|
+
data.tar.gz: 441a611dad33f158cefcb6448b4cde0b421ad08f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3bee9d96c32156e72c29f28d9fee0a8eedf98829b5385f52f9e672518b86a82db043f36fa2f776352a8ded0544d0dffb026337391134b87785c2f4dd3756119
|
7
|
+
data.tar.gz: 643039b55ffa03ed0d71c2160c63eff43b73132a1f594d2295b4b15a333266f08ed3c3805ebf8381ae2ec7142cf30af37468363bfa2dff5c9f6dbf9d682c303d
|
data/Manifest.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# backport_yield_self [![Build Status](https://travis-ci.org/koic/backport_yield_self.svg)](https://travis-ci.org/koic/backport_yield_self)
|
2
|
+
|
3
|
+
backport_yield_self is the backport of `Kernel#yield_self` in Ruby 2.5 to older Ruby versions.
|
4
|
+
|
5
|
+
The best way is to use Ruby 2.5 or later. Because you can use original `yield_self` method and so on.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add these lines to your application's Gemfile:
|
10
|
+
|
11
|
+
```
|
12
|
+
gem 'backport_yield_self'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```
|
18
|
+
$ bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```
|
24
|
+
$ gem install backport_yield_self
|
25
|
+
```
|
26
|
+
|
27
|
+
And require it as:
|
28
|
+
|
29
|
+
```
|
30
|
+
require 'backport_yield_self'
|
31
|
+
```
|
32
|
+
|
33
|
+
## Synopsis
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
"my string".yield_self {|s| s.upcase } #=> "MY STRING"
|
37
|
+
3.next.yield_self {|x| x**x }.to_s #=> "256"
|
38
|
+
```
|
39
|
+
|
40
|
+
## Supported Versions
|
41
|
+
|
42
|
+
* Ruby 2.2
|
43
|
+
* Ruby 2.3
|
44
|
+
* Ruby 2.4
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
backport_yield_self is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
57
|
+
|
58
|
+
### Get the original codes
|
59
|
+
|
60
|
+
* Kernel#yield_self [https://github.com/ruby/ruby/commit/cec0668](https://github.com/ruby/ruby/commit/cec0668209483a3f233574211c4b8fbd3d1d64b7)
|
61
|
+
|
62
|
+
## Special Thanks
|
63
|
+
|
64
|
+
* Ruby Development Team
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'hoe'
|
4
|
+
gem 'rake-compiler'
|
5
|
+
require 'rake/extensiontask'
|
6
|
+
|
7
|
+
name = 'backport_yield_self'
|
8
|
+
|
9
|
+
Hoe.plugin :gemspec
|
10
|
+
|
11
|
+
HOE = Hoe.spec name do
|
12
|
+
VERSION = BackportYieldSelf::VERSION
|
13
|
+
developer('Koichi ITO', 'koic.ito@gmail.com')
|
14
|
+
license 'MIT'
|
15
|
+
end
|
16
|
+
|
17
|
+
RET = Rake::ExtensionTask.new(name, HOE.spec) do |ext|
|
18
|
+
ext.lib_dir = File.join('lib', name)
|
19
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <ruby/intern.h>
|
3
|
+
|
4
|
+
static VALUE
|
5
|
+
rb_obj_size(VALUE self, VALUE args, VALUE obj)
|
6
|
+
{
|
7
|
+
return LONG2FIX(1);
|
8
|
+
}
|
9
|
+
|
10
|
+
/*!
|
11
|
+
* Make the object invisible from Ruby code.
|
12
|
+
*
|
13
|
+
* It is useful to let Ruby's GC manage your internal data structure --
|
14
|
+
* The object keeps being managed by GC, but \c ObjectSpace.each_object
|
15
|
+
* never yields the object.
|
16
|
+
*
|
17
|
+
* Note that the object also lose a way to call a method on it.
|
18
|
+
*
|
19
|
+
* \param[in] obj a Ruby object
|
20
|
+
* \sa rb_obj_reveal
|
21
|
+
*/
|
22
|
+
VALUE
|
23
|
+
rb_obj_hide(VALUE obj)
|
24
|
+
{
|
25
|
+
if (!SPECIAL_CONST_P(obj)) {
|
26
|
+
RBASIC_CLEAR_CLASS(obj);
|
27
|
+
}
|
28
|
+
return obj;
|
29
|
+
}
|
30
|
+
|
31
|
+
/*
|
32
|
+
* call-seq:
|
33
|
+
* obj.yield_self {|x| block } -> an_object
|
34
|
+
*
|
35
|
+
* Yields self to the block and returns the result of the block.
|
36
|
+
*
|
37
|
+
* "my string".yield_self {|s| s.upcase } #=> "MY STRING"
|
38
|
+
* 3.next.yield_self {|x| x**x }.to_s #=> "256"
|
39
|
+
*
|
40
|
+
*/
|
41
|
+
|
42
|
+
static VALUE
|
43
|
+
rb_obj_yield_self(VALUE obj)
|
44
|
+
{
|
45
|
+
RETURN_SIZED_ENUMERATOR(obj, 0, 0, rb_obj_size);
|
46
|
+
return rb_yield_values2(1, &obj);
|
47
|
+
}
|
48
|
+
|
49
|
+
void
|
50
|
+
Init_backport_yield_self(void)
|
51
|
+
{
|
52
|
+
#undef rb_intern
|
53
|
+
#define rb_intern(str) rb_intern_const(str)
|
54
|
+
|
55
|
+
rb_mKernel = rb_define_module("Kernel");
|
56
|
+
|
57
|
+
rb_define_method(rb_mKernel, "yield_self", rb_obj_yield_self, 0);
|
58
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
|
2
|
+
|
3
|
+
# :stopdoc:
|
4
|
+
|
5
|
+
require 'mkmf'
|
6
|
+
|
7
|
+
LIBDIR = RbConfig::CONFIG['libdir']
|
8
|
+
INCLUDEDIR = RbConfig::CONFIG['includedir']
|
9
|
+
|
10
|
+
$CFLAGS << " -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline"
|
11
|
+
|
12
|
+
HEADER_DIRS = [
|
13
|
+
# First search /opt/local for macports
|
14
|
+
'/opt/local/include',
|
15
|
+
|
16
|
+
# Then search /usr/local for people that installed from source
|
17
|
+
'/usr/local/include',
|
18
|
+
|
19
|
+
# Check the ruby install locations
|
20
|
+
INCLUDEDIR,
|
21
|
+
|
22
|
+
# Finally fall back to /usr
|
23
|
+
'/usr/include',
|
24
|
+
]
|
25
|
+
|
26
|
+
LIB_DIRS = [
|
27
|
+
# First search /opt/local for macports
|
28
|
+
'/opt/local/lib',
|
29
|
+
|
30
|
+
# Then search /usr/local for people that installed from source
|
31
|
+
'/usr/local/lib',
|
32
|
+
|
33
|
+
# Check the ruby install locations
|
34
|
+
LIBDIR,
|
35
|
+
|
36
|
+
# Finally fall back to /usr
|
37
|
+
'/usr/lib',
|
38
|
+
]
|
39
|
+
|
40
|
+
create_makefile('backport_yield_self/backport_yield_self')
|
41
|
+
|
42
|
+
# :startdoc:
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'backport_yield_self/backport_yield_self'
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: backport_yield_self
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Koichi ITO
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hoe
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
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: rake-compiler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0
|
55
|
+
description:
|
56
|
+
email: koic.ito@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions:
|
59
|
+
- ext/backport_yield_self/extconf.rb
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Manifest.txt
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- ext/backport_yield_self/backport_yield_self.c
|
66
|
+
- ext/backport_yield_self/extconf.rb
|
67
|
+
- lib/backport_yield_self.rb
|
68
|
+
homepage: https://github.com/koic/backport_yield_self
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message: |
|
73
|
+
backport_yield_self is the backport of Kernel#yield_self in Ruby 2.5 to older Ruby versions.
|
74
|
+
The best way is to use Ruby 2.5 or later.
|
75
|
+
Thanks.
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 2.2.0
|
84
|
+
- - "<"
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 2.5.0
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.6.14
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: backport_yield_self is the backport of Kernel#yield_self in Ruby 2.5 to older
|
98
|
+
Ruby versions.
|
99
|
+
test_files: []
|