Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Fix Ruby 1.9.2 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradIrwin committed Jun 27, 2011
1 parent 91e1f49 commit cee1278
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 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"
Expand Down
28 changes: 23 additions & 5 deletions lib/ampex.rb
@@ -1,18 +1,30 @@
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,
# and Metavariable#to_proc that makes &X work.
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
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion spec/ampex_spec.rb
Expand Up @@ -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]
Expand Down

0 comments on commit cee1278

Please sign in to comment.