summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mair <jrmair@gmail.com>2011-03-16 18:25:04 +1300
committerJohn Mair <jrmair@gmail.com>2011-03-16 18:25:04 +1300
commit67675b4bb5fe837968c582a18a12cc4cc0ca802f (patch)
tree4c5a1272a9b695b8e3e399e96fedfe96a989b53e
parentc8279c143d649e00da7929f52493e9e1fd9de0c9 (diff)
downloadmethod_source-67675b4bb5fe837968c582a18a12cc4cc0ca802f.tar.gz
version 0.4.0, added proper support for immediate values to
source_location in 1.8.
-rw-r--r--lib/method_source/source_location.rb14
-rw-r--r--lib/method_source/version.rb2
-rw-r--r--test/test.rb19
3 files changed, 34 insertions, 1 deletions
diff --git a/lib/method_source/source_location.rb b/lib/method_source/source_location.rb
index f1929e1..e018d74 100644
--- a/lib/method_source/source_location.rb
+++ b/lib/method_source/source_location.rb
@@ -44,6 +44,20 @@ module MethodSource
Class.new { include(method_owner) }
end
+ # deal with immediate values
+ case
+ when klass == Symbol
+ return :a.method(name).source_location
+ when klass == Fixnum
+ return 0.method(name).source_location
+ when klass == TrueClass
+ return true.method(name).source_location
+ when klass == FalseClass
+ return false.method(name).source_location
+ when klass == NilClass
+ return nil.method(name).source_location
+ end
+
begin
klass.allocate.method(name).source_location
rescue TypeError
diff --git a/lib/method_source/version.rb b/lib/method_source/version.rb
index 05234be..56956e7 100644
--- a/lib/method_source/version.rb
+++ b/lib/method_source/version.rb
@@ -1,3 +1,3 @@
module MethodSource
- VERSION = "0.3.5"
+ VERSION = "0.4.0"
end
diff --git a/test/test.rb b/test/test.rb
index 2a8eee2..5390de8 100644
--- a/test/test.rb
+++ b/test/test.rb
@@ -1,11 +1,30 @@
direc = File.dirname(__FILE__)
+require 'rubygems'
require 'bacon'
require "#{direc}/../lib/method_source"
require "#{direc}/test_helper"
describe MethodSource do
+ describe "source_location (testing 1.8 implementation)" do
+ it 'should return correct source_location for a method' do
+ method(:hello).source_location.first.should =~ /test_helper/
+ end
+
+ it 'should not raise for immediate instance methods' do
+ [Symbol, Fixnum, TrueClass, FalseClass, NilClass].each do |immediate_class|
+ lambda { immediate_class.instance_method(:to_s).source_location }.should.not.raise
+ end
+ end
+
+ it 'should not raise for immediate methods' do
+ [:a, 1, true, false, nil].each do |immediate|
+ lambda { immediate.method(:to_s).source_location }.should.not.raise
+ end
+ end
+ end
+
before do
@hello_module_source = " def hello; :hello_module; end\n"
@hello_singleton_source = "def $o.hello; :hello_singleton; end\n"