blankslate-2.1.2.4/ 0000755 0001750 0001750 00000000000 11677355351 013371 5 ustar boutil boutil blankslate-2.1.2.4/metadata.yml 0000644 0001750 0001750 00000003226 11677355351 015677 0 ustar boutil boutil --- !ruby/object:Gem::Specification
name: blankslate
version: !ruby/object:Gem::Version
prerelease:
version: 2.1.2.4
platform: ruby
authors:
- Jim Weirich
- David Masover
- Jack Danger Canty
autorequire:
bindir: bin
cert_chain: []
date: 2011-03-16 00:00:00 -07:00
default_executable:
dependencies:
- !ruby/object:Gem::Dependency
name: rspec
prerelease: false
requirement: &id001 !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
type: :development
version_requirements: *id001
- !ruby/object:Gem::Dependency
name: bundler
prerelease: false
requirement: &id002 !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
type: :development
version_requirements: *id002
description:
email: rubygems@6brand.com
executables: []
extensions: []
extra_rdoc_files: []
files:
- README
- Rakefile
- VERSION
- blankslate.gemspec
- lib/blankslate.rb
- spec/blankslate_spec.rb
has_rdoc: true
homepage: http://github.com/masover/blankslate
licenses: []
post_install_message:
rdoc_options: []
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
required_rubygems_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
requirements: []
rubyforge_project:
rubygems_version: 1.6.2
signing_key:
specification_version: 3
summary: BlankSlate extracted from Builder.
test_files:
- spec/blankslate_spec.rb
blankslate-2.1.2.4/spec/ 0000755 0001750 0001750 00000000000 11677355351 014323 5 ustar boutil boutil blankslate-2.1.2.4/spec/blankslate_spec.rb 0000644 0001750 0001750 00000001404 11677355351 020001 0 ustar boutil boutil require 'blankslate'
require 'rspec'
describe BlankSlate do
let(:blank_slate) { BlankSlate.new }
def call(obj, meth, *args)
BlankSlate.find_hidden_method(meth).bind(obj).call(*args)
end
describe "cleanliness" do
it "should not have many methods" do
BlankSlate.instance_methods.
map(&:to_s).sort.
should == ["__id__", "__send__", "instance_eval", "object_id"]
end
end
context "when methods are added to Object" do
after(:each) {
class Object
undef :foo
end
}
it "should still be blank" do
class Object
def foo
end
end
Object.new.foo
lambda {
BlankSlate.new.foo
}.should raise_error(NoMethodError)
end
end
end blankslate-2.1.2.4/lib/ 0000755 0001750 0001750 00000000000 11677355351 014137 5 ustar boutil boutil blankslate-2.1.2.4/lib/blankslate.rb 0000644 0001750 0001750 00000006547 11677355351 016620 0 ustar boutil boutil #!/usr/bin/env ruby
#--
# Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
# All rights reserved.
# Permission is granted for use, copying, modification, distribution,
# and distribution of modified versions of this work as long as the
# above copyright notice is included.
#++
######################################################################
# BlankSlate provides an abstract base class with no predefined
# methods (except for \_\_send__ and \_\_id__).
# BlankSlate is useful as a base class when writing classes that
# depend upon method_missing (e.g. dynamic proxies).
#
class BlankSlate
class << self
# Hide the method named +name+ in the BlankSlate class. Don't
# hide +instance_eval+ or any method beginning with "__".
def hide(name)
if instance_methods.map(&:to_sym).include?(name.to_sym) and
name !~ /^(__|instance_eval|object_id)/
@hidden_methods ||= {}
@hidden_methods[name.to_sym] = instance_method(name)
undef_method name
end
end
def find_hidden_method(name)
@hidden_methods ||= {}
@hidden_methods[name] || superclass.find_hidden_method(name)
end
# Redefine a previously hidden method so that it may be called on a blank
# slate object.
def reveal(name)
hidden_method = find_hidden_method(name)
fail "Don't know how to reveal method '#{name}'" unless hidden_method
define_method(name, hidden_method)
end
end
instance_methods.each { |m| hide(m) }
end
######################################################################
# Since Ruby is very dynamic, methods added to the ancestors of
# BlankSlate after BlankSlate is defined will show up in the
# list of available BlankSlate methods. We handle this by defining a
# hook in the Object and Kernel classes that will hide any method
# defined after BlankSlate has been loaded.
#
module Kernel
class << self
alias_method :blank_slate_method_added, :method_added
# Detect method additions to Kernel and remove them in the
# BlankSlate class.
def method_added(name)
result = blank_slate_method_added(name)
return result if self != Kernel
BlankSlate.hide(name)
result
end
end
end
######################################################################
# Same as above, except in Object.
#
class Object
class << self
alias_method :blank_slate_method_added, :method_added
# Detect method additions to Object and remove them in the
# BlankSlate class.
def method_added(name)
result = blank_slate_method_added(name)
return result if self != Object
BlankSlate.hide(name)
result
end
def find_hidden_method(name)
nil
end
end
end
######################################################################
# Also, modules included into Object need to be scanned and have their
# instance methods removed from blank slate. In theory, modules
# included into Kernel would have to be removed as well, but a
# "feature" of Ruby prevents late includes into modules from being
# exposed in the first place.
#
class Module
alias blankslate_original_append_features append_features
def append_features(mod)
result = blankslate_original_append_features(mod)
return result if mod != Object
instance_methods.each do |name|
BlankSlate.hide(name)
end
result
end
end blankslate-2.1.2.4/blankslate.gemspec 0000644 0001750 0001750 00000001455 11677355351 017063 0 ustar boutil boutil # -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "blankslate"
Gem::Specification.new do |s|
s.name = "blankslate"
s.version = File.read('VERSION')
s.platform = Gem::Platform::RUBY
s.summary = 'BlankSlate extracted from Builder.'
s.email = 'rubygems@6brand.com'
s.authors = ['Jim Weirich', 'David Masover', 'Jack Danger Canty']
s.email = "rubygems@6brand.com"
s.homepage = "http://github.com/masover/blankslate"
s.add_development_dependency 'rspec'
s.add_development_dependency 'bundler'
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
end
blankslate-2.1.2.4/VERSION 0000644 0001750 0001750 00000000007 11677355351 014436 0 ustar boutil boutil 2.1.2.4 blankslate-2.1.2.4/Rakefile 0000644 0001750 0001750 00000000371 11677355351 015037 0 ustar boutil boutil
require 'bundler'
Bundler::GemHelper.install_tasks
task :default => :spec
require 'rake/testtask'
Rake::TestTask.new(:spec) do |test|
test.libs << '.'
test.ruby_opts = ['-rubygems']
test.pattern = 'spec/*_spec.rb'
test.verbose = true
end
blankslate-2.1.2.4/README 0000644 0001750 0001750 00000002255 11677355351 014255 0 ustar boutil boutil BlankSlate
===
BlankSlate provides an abstract base class with no predefined
methods (except for \_\_send__ and \_\_id__).
BlankSlate is useful as a base class when writing classes that
depend upon method_missing (e.g. dynamic proxies).
Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
All rights reserved.
Extracted from Builder because, for no conceivable reason,
blankslate isn't in its own gem. Gemified by David Masover,
moved to gemcutter by Jack Danger Canty (gemcutter@6brand.com
if you'd like to own this gem).
Explanation on extraction from David Masover:
So, Builder seems to have the most complete implementation of
BlankSlate, short of Ruby 1.9's BasicObject. The problem is,
this is part of Builder, and still inside the Builder gem.
It's especially frustrating, because the Builder source
(lib/builder/blankslate.rb) seems to acknowledge that there
should be a separate gem. But the only reference I can find
refers to onestepback.org's gem repository, which isn't working.
So I built my own. I'll try to keep it up to date with Builder.
The first three parts of the version number are
the Builder version; the last part is my revision.