Permalink
Browse files

CHANGE: Move attic/mixins content to attic.rb

  • Loading branch information...
1 parent 4cdf46f commit 3e768c2114a44fa8517d86bb9a43cdbc6f43992a @delano committed Feb 11, 2011
Showing with 73 additions and 73 deletions.
  1. +1 −0 CHANGES.txt
  2. +0 −1 attic.gemspec
  3. +72 −2 lib/attic.rb
  4. +0 −70 lib/attic/mixins.rb
View
@@ -4,6 +4,7 @@ ATTIC, CHANGES
* FIXED: Don't redefine Object::NOMETACLASS
* CHANGE: Updated tests to Tryouts 2
+* CHANGE: Move attic/mixins content to attic.rb
#### 0.5.2 (2010-02-15) ###############################
View
@@ -35,7 +35,6 @@
Rakefile
attic.gemspec
lib/attic.rb
- lib/attic/mixins.rb
try/01_mixins_tryouts.rb
try/10_attic_tryouts.rb
try/20_accessing_tryouts.rb
View
@@ -1,12 +1,82 @@
-require 'attic/mixins'
+class NoMetaClass < RuntimeError
+end
+
+# = Object
+#
+# These methods are copied directly from _why's metaid.rb.
+# See: http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
+class Object
+
+ unless defined?(::Object::NOMETACLASS)
+ # An Array of classes which do not have metaclasses.
+ NOMETACLASS = [Symbol, Fixnum].freeze
+ end
+
+ def nometaclass?
+ NOMETACLASS.member?(self)
+ end
+
+ def metaclass?
+ !NOMETACLASS.member?(self.class)
+ end
+
+ # A convenient method for getting the metaclass of the current object.
+ # i.e.
+ #
+ # class << self; self; end;
+ #
+ # NOTE: Some Ruby class do not have meta classes (see: NOMETACLASS).
+ # For these classes, this method returns the class itself. That means
+ # the instance variables will stored in the class itself.
+ def metaclass
+ if !self.metaclass?
+ raise NoMetaClass, self
+ else
+ class << self; self; end;
+ end
+ end
+
+ # Execute a block +&blk+ within the metaclass of the current object.
+ def meta_eval &blk; metaclass.instance_eval &blk; end
+
+ # Add an instance method called +name+ to metaclass for the current object.
+ # This is useful because it will be available as a singleton method
+ # to all subclasses too.
+ def meta_def name, &blk
+ meta_eval { define_method name, &blk }
+ end
+
+ # Add a class method called +name+ for the current object's class. This
+ # isn't so special but it maintains consistency with meta_def.
+ def class_def name, &blk
+ class_eval { define_method name, &blk }
+ end
+
+
+ # A convenient method for getting the metaclass of the metaclass
+ # i.e.
+ #
+ # self.metaclass.metaclass
+ #
+ def metametaclass; self.metaclass.metaclass; end
+
+ def metameta_eval &blk; metametaclass.instance_eval &blk; end
+
+ def metameta_def name, &blk
+ metameta_eval { define_method name, &blk }
+ end
+
+end
+
+
# = Attic
#
# A place to store instance variables.
#
module Attic
- VERSION = '0.5.2' unless defined?(VERSION)
+ VERSION = '0.5.3' unless defined?(VERSION)
module InstanceMethods
def attic_variables
View
@@ -1,70 +0,0 @@
-class NoMetaClass < RuntimeError
-end
-
-# = Object
-#
-# These methods are copied directly from _why's metaid.rb.
-# See: http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
-class Object
-
- unless defined?(::Object::NOMETACLASS)
- # An Array of classes which do not have metaclasses.
- NOMETACLASS = [Symbol, Fixnum].freeze
- end
-
- def nometaclass?
- NOMETACLASS.member?(self)
- end
-
- def metaclass?
- !NOMETACLASS.member?(self.class)
- end
-
- # A convenient method for getting the metaclass of the current object.
- # i.e.
- #
- # class << self; self; end;
- #
- # NOTE: Some Ruby class do not have meta classes (see: NOMETACLASS).
- # For these classes, this method returns the class itself. That means
- # the instance variables will stored in the class itself.
- def metaclass
- if !self.metaclass?
- raise NoMetaClass, self
- else
- class << self; self; end;
- end
- end
-
- # Execute a block +&blk+ within the metaclass of the current object.
- def meta_eval &blk; metaclass.instance_eval &blk; end
-
- # Add an instance method called +name+ to metaclass for the current object.
- # This is useful because it will be available as a singleton method
- # to all subclasses too.
- def meta_def name, &blk
- meta_eval { define_method name, &blk }
- end
-
- # Add a class method called +name+ for the current object's class. This
- # isn't so special but it maintains consistency with meta_def.
- def class_def name, &blk
- class_eval { define_method name, &blk }
- end
-
-
- # A convenient method for getting the metaclass of the metaclass
- # i.e.
- #
- # self.metaclass.metaclass
- #
- def metametaclass; self.metaclass.metaclass; end
-
- def metameta_eval &blk; metametaclass.instance_eval &blk; end
-
- def metameta_def name, &blk
- metameta_eval { define_method name, &blk }
- end
-
-end
-

0 comments on commit 3e768c2

Please sign in to comment.