Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix Ruby 1.9.2 support.

  • Loading branch information...
commit cee1278d14a3d41a2f49c3454b648616fe0cecb1 1 parent 91e1f49
@ConradIrwin ConradIrwin authored
Showing with 25 additions and 7 deletions.
  1. +1 −1  ampex.gemspec
  2. +23 −5 lib/ampex.rb
  3. +1 −1  spec/ampex_spec.rb
View
2  ampex.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "ampex"
- s.version = "1.1.2"
+ s.version = "1.2.0"
s.platform = Gem::Platform::RUBY
s.author = "Conrad Irwin"
s.email = "conrad.irwin@gmail.com"
View
28 lib/ampex.rb
@@ -1,10 +1,22 @@
-require 'blankslate'
-
# Copyright 2010 Conrad Irwin <conrad.irwin@gmail.com> MIT License
#
# For detailed usage notes, please see README.markdown
-#
-class Metavariable < BlankSlate
+
+# NOTE: Ruby 1.9 seems to provide a default blank slate that isn't
+# very blank, luckily it also provides a BasicObject which is pretty
+# basic.
+if defined? BasicObject
+ superclass = BasicObject
+else
+ require 'rubygems'
+ require 'blankslate'
+ superclass = BlankSlate
+end
+
+class Metavariable < superclass
+ # Take a local copy of these as constant lookup is destroyed by BasicObject.
+ Metavariable = self
+ Thread = ::Thread
# When you pass an argument with & in ruby, you're actually calling #to_proc
# on the object. So it's Symbol#to_proc that makes the &:to_s trick work,
@@ -12,7 +24,7 @@ class Metavariable < BlankSlate
attr_reader :to_proc
def initialize(&block)
- @to_proc = block || lambda{|x| x}
+ @to_proc = block || ::Proc.new{|x| x}
end
# Each time a method is called on a Metavariable, we want to create a new
@@ -32,6 +44,12 @@ def method_missing(name, *args, &block)
mv
end
+ # BlankSlate and BasicObject have different sets of methods that you don't want.
+ # let's remove them all.
+ instance_methods.each do |method|
+ undef_method method unless %w(method_missing to_proc __send__ __id__).include? method.to_s
+ end
+
private
# In order to support assignment via &X (expressions of the form &X['one'] = 2),
View
2  spec/ampex_spec.rb
@@ -63,7 +63,7 @@ def intercept(b)
it "should preserve existing #to_proc in an object's singleton class" do
a = Object.new
class << a
- def to_proc; lambda { 3 }; end
+ def to_proc; lambda { |x| 3 }; end
end
[1].map(&a).should == [3]
Please sign in to comment.
Something went wrong with that request. Please try again.