nakajima-nakajima 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/nakajima.rb +3 -1
- data/lib/nakajima/core_ext/object.rb +8 -0
- data/lib/nakajima/likewise.rb +32 -0
- metadata +5 -2
- data/lib/nakajima/core_ext/proc.rb +0 -13
data/lib/nakajima.rb
CHANGED
@@ -8,7 +8,9 @@ require 'metaid'
|
|
8
8
|
require 'nakajima/core_ext/array'
|
9
9
|
require 'nakajima/core_ext/kernel'
|
10
10
|
require 'nakajima/core_ext/object'
|
11
|
-
require 'nakajima/core_ext/proc'
|
12
11
|
require 'nakajima/core_ext/symbol'
|
13
12
|
|
13
|
+
# otherwise
|
14
|
+
require 'nakajima/likewise'
|
15
|
+
|
14
16
|
module Nakajima; end
|
@@ -3,6 +3,14 @@ module Nakajima
|
|
3
3
|
def try(method_id, *args, &block)
|
4
4
|
respond_to?(method_id) ? send(method_id, *args, &block) : nil
|
5
5
|
end
|
6
|
+
|
7
|
+
def not
|
8
|
+
@not ||= blank_context(:receiver => self) do
|
9
|
+
def method_missing(sym, *args, &block)
|
10
|
+
not @receiver.send(sym, *args, &block)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
6
14
|
|
7
15
|
# Like JavaScript, but in Ruby...
|
8
16
|
def with(hash)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# likewise require
|
2
|
+
# by Pat Nakajima
|
3
|
+
# because I've been drinking more than Jack Barnette
|
4
|
+
# and
|
5
|
+
# to annoy John Susser and Aaron Peterson
|
6
|
+
#
|
7
|
+
# use to require files relative to the current file:
|
8
|
+
#
|
9
|
+
# likewise do
|
10
|
+
# require "foo" # require current-dir/lib
|
11
|
+
# require "lib/foo" # require current-dir/lib/foo
|
12
|
+
# end
|
13
|
+
module Kernel
|
14
|
+
def likewise(&blk)
|
15
|
+
Class.new {
|
16
|
+
instance_methods.each { |m| undef_method(m) unless m.to_s =~ /__/ }
|
17
|
+
|
18
|
+
def initialize(&block)
|
19
|
+
@outside = eval('self', block.binding)
|
20
|
+
Object.instance_method(:instance_eval).bind(self).call(&block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def require(path)
|
24
|
+
super(File.join(File.dirname(caller.first.split(':').first), path))
|
25
|
+
end
|
26
|
+
|
27
|
+
def method_missing(sym, *args, &block)
|
28
|
+
@outside.send(sym, *args, &block)
|
29
|
+
end
|
30
|
+
}.new(&blk)
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nakajima-nakajima
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Nakajima
|
@@ -14,6 +14,7 @@ default_executable:
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: colored
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
@@ -23,6 +24,7 @@ dependencies:
|
|
23
24
|
version:
|
24
25
|
- !ruby/object:Gem::Dependency
|
25
26
|
name: metaid
|
27
|
+
type: :runtime
|
26
28
|
version_requirement:
|
27
29
|
version_requirements: !ruby/object:Gem::Requirement
|
28
30
|
requirements:
|
@@ -32,6 +34,7 @@ dependencies:
|
|
32
34
|
version:
|
33
35
|
- !ruby/object:Gem::Dependency
|
34
36
|
name: rr
|
37
|
+
type: :runtime
|
35
38
|
version_requirement:
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
@@ -49,11 +52,11 @@ extra_rdoc_files: []
|
|
49
52
|
|
50
53
|
files:
|
51
54
|
- lib/nakajima
|
55
|
+
- lib/nakajima/likewise.rb
|
52
56
|
- lib/nakajima/core_ext
|
53
57
|
- lib/nakajima/core_ext/array.rb
|
54
58
|
- lib/nakajima/core_ext/kernel.rb
|
55
59
|
- lib/nakajima/core_ext/object.rb
|
56
|
-
- lib/nakajima/core_ext/proc.rb
|
57
60
|
- lib/nakajima/core_ext/symbol.rb
|
58
61
|
- lib/nakajima/ui
|
59
62
|
- lib/nakajima/ui/progress.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# from activesupport
|
2
|
-
class Proc
|
3
|
-
def bind(object)
|
4
|
-
block, time = self, Time.now
|
5
|
-
(class << object; self end).class_eval do
|
6
|
-
method_name = "__bind_#{time.to_i}_#{time.usec}"
|
7
|
-
define_method(method_name, &block)
|
8
|
-
method = instance_method(method_name)
|
9
|
-
remove_method(method_name)
|
10
|
-
method
|
11
|
-
end.bind(object)
|
12
|
-
end
|
13
|
-
end
|