method_source 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ method_source
6
6
  _retrieve the sourcecode for a method_
7
7
 
8
8
  `method_source` is a utility to return a method's sourcecode as a
9
- Ruby string.
9
+ Ruby string. Also returns `Proc` and `Lambda` sourcecode.
10
10
 
11
11
  It is written in pure Ruby (no C).
12
12
 
@@ -17,8 +17,8 @@ It is written in pure Ruby (no C).
17
17
  * Read the [documentation](http://rdoc.info/github/banister/method_source/master/file/README.markdown)
18
18
  * See the [source code](http://github.com/banister/method_source)
19
19
 
20
- example:
21
- ---------
20
+ Example: methods
21
+ ----------------
22
22
 
23
23
  Set.instance_method(:merge).source.display
24
24
  # =>
@@ -35,7 +35,7 @@ example:
35
35
  Limitations:
36
36
  ------------
37
37
 
38
- * Only works with Ruby 1.9+
38
+ * Only works with Ruby 1.9+ (YARV)
39
39
  * Cannot return source for C methods.
40
40
  * Cannot return source for dynamically defined methods.
41
41
 
@@ -92,3 +92,7 @@ end
92
92
  class UnboundMethod
93
93
  include MethodSource::MethodExtensions
94
94
  end
95
+
96
+ class Proc
97
+ include MethodSource::MethodExtensions
98
+ end
@@ -1,3 +1,3 @@
1
1
  module MethodSource
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -4,29 +4,51 @@ require 'bacon'
4
4
  require "#{direc}/../lib/method_source"
5
5
 
6
6
  hello_source = "def hello; :hello; end\n"
7
+ lambda_source = "MyLambda = lambda { :lambda }\n"
8
+ proc_source = "MyProc = Proc.new { :proc }\n"
7
9
 
8
10
  def hello; :hello; end
9
11
 
10
- describe MethodSource do
12
+ MyLambda = lambda { :lambda }
13
+ MyProc = Proc.new { :proc }
11
14
 
12
- it 'should define methods on both Method and UnboundMethod' do
15
+ describe MethodSource do
16
+ it 'should define methods on Method and UnboundMethod and Proc' do
13
17
  Method.method_defined?(:source).should == true
14
18
  UnboundMethod.method_defined?(:source).should == true
19
+ Proc.method_defined?(:source).should == true
15
20
  end
16
-
17
- if RUBY_VERSION =~ /1.9/
18
- it 'should return source for method' do
19
- method(:hello).source.should == hello_source
20
- end
21
21
 
22
- it 'should raise for C methods' do
23
- lambda { method(:puts).source }.should.raise RuntimeError
24
- end
22
+ describe "Methods" do
23
+ if RUBY_VERSION =~ /1.9/
24
+ it 'should return source for method' do
25
+ method(:hello).source.should == hello_source
26
+ end
25
27
 
26
- else
27
- it 'should raise on #source' do
28
- lambda { method(:hello).source }.should.raise RuntimeError
28
+ it 'should raise for C methods' do
29
+ lambda { method(:puts).source }.should.raise RuntimeError
30
+ end
31
+
32
+ else
33
+ it 'should raise on #source' do
34
+ lambda { method(:hello).source }.should.raise RuntimeError
35
+ end
29
36
  end
30
37
  end
31
- end
32
38
 
39
+ describe "Lambdas and Procs" do
40
+ if RUBY_VERSION =~ /1.9/
41
+ it 'should return source for proc' do
42
+ MyProc.source.should == proc_source
43
+ end
44
+
45
+ it 'should return source for lambda' do
46
+ MyLambda.source.should == lambda_source
47
+ end
48
+ else
49
+ it 'should raise on #source' do
50
+ lambda { method(:hello).source }.should.raise RuntimeError
51
+ end
52
+ end
53
+ end
54
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: method_source
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Mair (banisterfiend)