method_source 0.1.1 → 0.1.4
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.
- data/README.markdown +4 -1
- data/lib/method_source.rb +5 -17
- data/lib/method_source/version.rb +1 -1
- metadata +2 -5
data/README.markdown
CHANGED
@@ -5,13 +5,16 @@ method_source
|
|
5
5
|
|
6
6
|
_retrieve the sourcecode for a method_
|
7
7
|
|
8
|
+
*NOTE:* This is nothing fancy; it simply utilizes `Method#source_location`
|
9
|
+
in Ruby 1.9
|
10
|
+
|
8
11
|
`method_source` is a utility to return a method's sourcecode as a
|
9
12
|
Ruby string. Also returns `Proc` and `Lambda` sourcecode.
|
10
13
|
|
11
14
|
It is written in pure Ruby (no C).
|
12
15
|
|
13
16
|
`method_source` provides the `source` method to the `Method` and
|
14
|
-
`UnboundMethod` classes.
|
17
|
+
`UnboundMethod` and `Proc` classes.
|
15
18
|
|
16
19
|
* Install the [gem](https://rubygems.org/gems/method_source): `gem install method_source`
|
17
20
|
* Read the [documentation](http://rdoc.info/github/banister/method_source/master/file/README.markdown)
|
data/lib/method_source.rb
CHANGED
@@ -6,6 +6,10 @@ direc = File.dirname(__FILE__)
|
|
6
6
|
require 'stringio'
|
7
7
|
require "#{direc}/method_source/version"
|
8
8
|
|
9
|
+
if RUBY_VERSION =~ /1.9/
|
10
|
+
require 'ripper'
|
11
|
+
end
|
12
|
+
|
9
13
|
module MethodSource
|
10
14
|
|
11
15
|
# Helper method used to find end of method body
|
@@ -13,23 +17,7 @@ module MethodSource
|
|
13
17
|
# correctness
|
14
18
|
# @return [Boolean]
|
15
19
|
def self.valid_expression?(code)
|
16
|
-
|
17
|
-
RubyVM::InstructionSequence.new(code)
|
18
|
-
end
|
19
|
-
rescue Exception
|
20
|
-
false
|
21
|
-
else
|
22
|
-
true
|
23
|
-
end
|
24
|
-
|
25
|
-
# Helper method used to suppress stderr output by the
|
26
|
-
# `RubyVM::InstructionSequence` method
|
27
|
-
# @yield The block where stderr is suppressed
|
28
|
-
def self.suppress_stderr
|
29
|
-
real_stderr, $stderr = $stderr, StringIO.new
|
30
|
-
yield
|
31
|
-
ensure
|
32
|
-
$stderr = real_stderr
|
20
|
+
!!Ripper::SexpBuilder.new(code).parse
|
33
21
|
end
|
34
22
|
|
35
23
|
# Helper method responsible for opening source file and advancing to
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_source
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 25
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- John Mair (banisterfiend)
|
@@ -47,7 +46,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
46
|
requirements:
|
48
47
|
- - ">="
|
49
48
|
- !ruby/object:Gem::Version
|
50
|
-
hash: 3
|
51
49
|
segments:
|
52
50
|
- 0
|
53
51
|
version: "0"
|
@@ -56,7 +54,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
54
|
requirements:
|
57
55
|
- - ">="
|
58
56
|
- !ruby/object:Gem::Version
|
59
|
-
hash: 3
|
60
57
|
segments:
|
61
58
|
- 0
|
62
59
|
version: "0"
|