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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c2091083a33b7cbb099c9ee0b6446cfbcee813c
4
- data.tar.gz: 617724d273b7cfdd320a97e91dbc4f5c1efb8e08
3
+ metadata.gz: eee16bf05685c3be76a254f972ae12e409922422
4
+ data.tar.gz: 2bdd20b5c59ee42e80026662032f58d3b09572e0
5
5
  SHA512:
6
- metadata.gz: 683f4ce846a8d044a1c9d63818a0ff0e6f65b17ab92e6861329ac75d56ff133504a3a9a700890df49a3790aa9e2b2cb49183d07f0561518a1d1358b8d824420e
7
- data.tar.gz: 7142cd10f757a4b9e8bc90c758b7d83e84904d135f84d305aea99dd9b78f89a0afa0ab18cc3d2695e73182ff0634743ecb316f20d363b03e5cba321e027882a4
6
+ metadata.gz: e0ed16d9f99c7f02fcb71a1ba5db49a6ee7d229cc05cca4c931d09bf1a5211f7dd6463547d87eb9829b47825722535c179d1ba2b4733531b755caadf903a7a90
7
+ data.tar.gz: 3e5742a124763100d95cff33b42d63286432cb3dba52fbb41013c79cfadd6d6f104d89abc6f06c593e4e6dbcf1d1ed673cec721556fd3410bdfb2d5b3b3bff5c
@@ -1,5 +1,11 @@
1
1
  ## CHANGELOG
2
2
 
3
+ ### 0.1.1
4
+
5
+ * Improve performance
6
+
7
+ * supress _ in IRB
8
+
3
9
  ### 0.1.0
4
10
 
5
11
  * Inital release
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in kasen.gemspec
3
+ gem 'benchmark-ips'
4
+ gem 'pry'
4
5
  gemspec
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
- # is equivalent for
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
- ['0', '1', '2'].select &_.to_i.zero?
17
+ &_.to_i.zero?
14
18
  # is equivalent for
15
- ['0', '1', '2'].select { |s| s.to_i.zero? },
19
+ { |s| s.to_i.zero? }
16
20
 
17
- [['1', '2'], ['3', '4']].map { |ary| ary.select { |n| n.to_i.eql?(1) } },
21
+ &_.select(&_.to_i.eql?(1))
18
22
  # is equivalent for
19
- [['1', '2'], ['3', '4']].map(&_.select(&_.to_i.eql?(1)))
23
+ { |ary| ary.select { |n| n.to_i.eql?(1) } }
20
24
  ```
21
25
 
22
- note: you can use `k` instead of `_` in IRB.
23
-
24
- ## Installation
26
+ calling any method with `_` produces `Proc` object which is equivalent for calling methods in `Proc` body.
25
27
 
26
- Add this line to your application's Gemfile:
28
+ note: you can use `k` instead of `_` in IRB.
27
29
 
28
30
  ```ruby
29
- gem 'kasen'
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
- And then execute:
40
+ ## Doc
33
41
 
34
- $ bundle
42
+ ### Installation
43
+ Have it your way.
35
44
 
36
- Or install it yourself as:
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
@@ -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.9"
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
@@ -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
- class Kasen
11
- # Disable all build-in methods
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
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
- def initialize
21
- @_calling_methods = []
22
- end
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
- def to_proc
25
- Proc.new { |o|
26
- @_calling_methods.each do |calling_method|
27
- o = calling_method.call(o)
28
- end
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
- def method_missing(name, *args, &block)
34
- @_calling_methods << Proc.new { |o|
35
- o.send(name, *args, &block)
36
- }
37
- self
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
@@ -1,3 +1,3 @@
1
- class Kasen
2
- VERSION = "0.1.0"
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.0
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-24 00:00:00.000000000 Z
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.9'
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.9'
26
+ version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement