kasen 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile +2 -1
- data/README.md +33 -14
- data/Rakefile +21 -0
- data/kasen.gemspec +1 -1
- data/lib/kasen.rb +39 -24
- data/lib/kasen/version.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eee16bf05685c3be76a254f972ae12e409922422
|
4
|
+
data.tar.gz: 2bdd20b5c59ee42e80026662032f58d3b09572e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0ed16d9f99c7f02fcb71a1ba5db49a6ee7d229cc05cca4c931d09bf1a5211f7dd6463547d87eb9829b47825722535c179d1ba2b4733531b755caadf903a7a90
|
7
|
+
data.tar.gz: 3e5742a124763100d95cff33b42d63286432cb3dba52fbb41013c79cfadd6d6f104d89abc6f06c593e4e6dbcf1d1ed673cec721556fd3410bdfb2d5b3b3bff5c
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,42 +1,61 @@
|
|
1
1
|
# Kasen
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/kasen.svg)](http://badge.fury.io/rb/kasen)
|
4
|
+
[![Build Status](https://travis-ci.org/gogotanaka/_.svg)](https://travis-ci.org/gogotanaka/_)
|
5
|
+
|
3
6
|
![kasen.png](https://qiita-image-store.s3.amazonaws.com/0/30440/7ac5c816-ad6d-dd62-1783-a2c435455fde.png)
|
4
7
|
|
5
8
|
下線(Kasen) ... Underscore.
|
6
9
|
|
7
10
|
```ruby
|
8
11
|
require 'kasen'
|
12
|
+
|
9
13
|
[[1, 2], [3, 4]].map &_[1]
|
10
|
-
|
11
|
-
[[1, 2], [3, 4]].map { |ary| ary[1] }
|
14
|
+
#=> [2, 4]
|
15
|
+
# is equivalent for [[1, 2], [3, 4]].map { |ary| ary[1] }
|
12
16
|
|
13
|
-
|
17
|
+
&_.to_i.zero?
|
14
18
|
# is equivalent for
|
15
|
-
|
19
|
+
{ |s| s.to_i.zero? }
|
16
20
|
|
17
|
-
|
21
|
+
&_.select(&_.to_i.eql?(1))
|
18
22
|
# is equivalent for
|
19
|
-
|
23
|
+
{ |ary| ary.select { |n| n.to_i.eql?(1) } }
|
20
24
|
```
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
## Installation
|
26
|
+
calling any method with `_` produces `Proc` object which is equivalent for calling methods in `Proc` body.
|
25
27
|
|
26
|
-
|
28
|
+
note: you can use `k` instead of `_` in IRB.
|
27
29
|
|
28
30
|
```ruby
|
29
|
-
|
31
|
+
['0', '1', '2'].select &_.to_i.zero?
|
32
|
+
#=> ["0"]
|
33
|
+
# is equivalent for ['0', '1', '2'].select { |s| s.to_i.zero? }
|
34
|
+
|
35
|
+
[['1', '2'], ['3', '4']].map &_.select(&_.to_i.eql?(1))
|
36
|
+
#=> [["1"], []]
|
37
|
+
# is equivalent for [['1', '2'], ['3', '4']].map { |ary| ary.select { |n| n.to_i.eql?(1) } }
|
30
38
|
```
|
31
39
|
|
32
|
-
|
40
|
+
## Doc
|
33
41
|
|
34
|
-
|
42
|
+
### Installation
|
43
|
+
Have it your way.
|
35
44
|
|
36
|
-
|
45
|
+
$ echo "gem 'kasen'" >> Gemfile; bundle
|
46
|
+
|
47
|
+
or
|
37
48
|
|
38
49
|
$ gem install kasen
|
39
50
|
|
51
|
+
### What dose `_`(`Kernel#_`) do?
|
52
|
+
|
53
|
+
`_`(`Kernel#_`) just returns empty object `Kasen.new`, all of which methods has been undefined expect for `Kasen#to_proc`, `Kasen#method_missing`.
|
54
|
+
|
55
|
+
and say, when `_` call `#to_i`(`_.to_i`), `Kasen#method_missing` store context(method_name, args, blokc) recursively.
|
56
|
+
|
57
|
+
And finnaly `Kasen#to_proc` returns all contexts as a block.
|
58
|
+
|
40
59
|
## Development
|
41
60
|
|
42
61
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -5,4 +5,25 @@ Rake::TestTask.new(:test) do |t|
|
|
5
5
|
t.libs << "test"
|
6
6
|
end
|
7
7
|
|
8
|
+
# Benchmark
|
9
|
+
#-----------------------------------------------
|
10
|
+
desc "Compare with pure ruby"
|
11
|
+
task :benchmark do
|
12
|
+
require "benchmark/ips"
|
13
|
+
require "kasen"
|
14
|
+
require "kasen"
|
15
|
+
|
16
|
+
puts "ruby version: #{RUBY_VERSION}"
|
17
|
+
puts "Kasen version: #{Kasen::VERSION}"
|
18
|
+
|
19
|
+
|
20
|
+
Benchmark.ips do |x|
|
21
|
+
x.report('Pure Ruby') { [1, 2, 3].map { |n| n + 1 } }
|
22
|
+
x.report('Kasen') { [1, 2, 3].map &k.+(1) }
|
23
|
+
|
24
|
+
x.compare!
|
25
|
+
end
|
26
|
+
end
|
27
|
+
task bm: :benchmark
|
28
|
+
|
8
29
|
task :default => :test
|
data/kasen.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
|
24
24
|
# end
|
25
25
|
|
26
|
-
spec.add_development_dependency "bundler", "~> 1.
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
28
|
spec.add_development_dependency "minitest"
|
29
29
|
end
|
data/lib/kasen.rb
CHANGED
@@ -2,38 +2,53 @@ require "kasen/version"
|
|
2
2
|
|
3
3
|
module Kernel
|
4
4
|
def k
|
5
|
-
Kasen.new
|
5
|
+
Kasen::Context.new
|
6
6
|
end
|
7
7
|
alias _ k
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
module Kasen
|
11
|
+
class EmptyObject
|
12
|
+
verbose, $VERBOSE = $VERBOSE, nil
|
13
|
+
begin
|
14
|
+
instance_methods(true).each { |meth| undef_method(meth) }
|
15
|
+
private_instance_methods(true).each { |meth| undef_method(meth) }
|
16
|
+
ensure
|
17
|
+
$VERBOSE = verbose
|
18
|
+
end
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
class Context < EmptyObject
|
22
|
+
def initialize
|
23
|
+
@__kasen__ = Proc.new { |o| o }
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_proc
|
27
|
+
@__kasen__
|
28
|
+
end
|
23
29
|
|
24
|
-
|
25
|
-
|
26
|
-
@
|
27
|
-
|
28
|
-
|
29
|
-
o
|
30
|
-
}
|
30
|
+
def method_missing(name, *args, &block)
|
31
|
+
__kasen__ = @__kasen__
|
32
|
+
@__kasen__ = Proc.new { |o| (__kasen__.(o)).send(name, *args, &block) }
|
33
|
+
self
|
34
|
+
end
|
31
35
|
end
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
class ContextGenerator < EmptyObject
|
38
|
+
def initialize
|
39
|
+
end
|
40
|
+
|
41
|
+
def method_missing(name, *args, &block)
|
42
|
+
Kasen::Context.new.send(name, *args, &block)
|
43
|
+
end
|
38
44
|
end
|
39
45
|
end
|
46
|
+
|
47
|
+
if defined?(IRB::Context)
|
48
|
+
class IRB::Context
|
49
|
+
def set_last_value(value)
|
50
|
+
@last_value = value
|
51
|
+
@workspace.evaluate self, "_ = Kasen::ContextGenerator.new"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/kasen/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.1.
|
1
|
+
module Kasen
|
2
|
+
VERSION = "0.1.1"
|
3
3
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kasen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gogotanaka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|