binder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,30 @@
1
+ = Installation
2
+
3
+ # gem install binder
4
+
5
+ = Use
6
+
7
+ # irb
8
+ >> require 'binder'
9
+ ==> true
10
+
11
+ >> def speak
12
+ >> "why should i?"
13
+ >> end
14
+ ==> nil
15
+
16
+ >> class Dog
17
+ >> def speak
18
+ >> "ruff!"
19
+ >> end
20
+ >> end
21
+ ==> nil
22
+
23
+ >> command = proc { speak }
24
+ ==> #<Proc:0x012c6a04@(irb):28>
25
+
26
+ >> command.call
27
+ ==> "why should i?"
28
+
29
+ >> command.bind_to(Dog.new).call
30
+ ==> "ruff!"
@@ -0,0 +1,7 @@
1
+ class Proc
2
+ def bind_to(some_object)
3
+ Proc.new do
4
+ some_object.instance_eval(&self)
5
+ end
6
+ end
7
+ end
data/lib/binder.rb ADDED
@@ -0,0 +1 @@
1
+ require 'binder/proc'
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Proc do
4
+ describe "#bind_to" do
5
+ it "should return a proc bound to a new context" do
6
+ def speak
7
+ "why should i?"
8
+ end
9
+
10
+ class Dog
11
+ def speak
12
+ "ruff!"
13
+ end
14
+ end
15
+
16
+ trick = proc { speak }
17
+
18
+ trick.call.should == "why should i?"
19
+ trick.bind_to(Dog.new).call.should == "ruff!"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift './lib'
2
+ require 'binder'
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: binder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matt Parker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-20 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Binder allows to evaluate a proc in a closure other than the one in which it was created. It also includes a method :bind to DRY up code for anyone creating a domain specific language.
17
+ email: moonmaster9000@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - README.rdoc
26
+ - lib/binder.rb
27
+ - lib/binder/proc.rb
28
+ has_rdoc: true
29
+ homepage: http://github.com/moonmaster9000/binder
30
+ licenses: []
31
+
32
+ post_install_message:
33
+ rdoc_options:
34
+ - --charset=UTF-8
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project:
52
+ rubygems_version: 1.3.5
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: A tool for rebinding your ruby procs, with a helper for DSL creaters.
56
+ test_files:
57
+ - spec/binder/proc_spec.rb
58
+ - spec/spec_helper.rb