Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed testname

  • Loading branch information...
commit 27642c2307f06400b9c1d0a51a8d44607f90a349 1 parent 15a3215
@sathish316 sathish316 authored
Showing with 84 additions and 84 deletions.
  1. +42 −42 koans/about_metaclass.rb
  2. +42 −42 src/about_metaclass.rb
View
84 koans/about_metaclass.rb
@@ -4,7 +4,7 @@
# http://dannytatom.github.com/metaid/
class AboutMetaclass < EdgeCase::Koan
-
+
class MailTruck
attr_accessor :driver, :route
def initialize(driver = nil, route = nil)
@@ -13,9 +13,9 @@ def initialize(driver = nil, route = nil)
end
def setup
- @truck = MailTruck.new("Harold", ['12 Corrigan way', '23 Antler Ave'])
+ @truck = MailTruck.new("Harold", ['12 Corrigan way', '23 Antler Ave'])
end
-
+
def test_class_of_an_object
assert_equal __, @truck.class
end
@@ -23,7 +23,7 @@ def test_class_of_an_object
def test_class_of_a_class
assert_equal __, MailTruck.class
end
-
+
def test_object_is_a_storage_for_variables
assert_equal __, @truck.driver
end
@@ -40,8 +40,8 @@ def test_attr_accessor_defines_reader_and_writer
def test_classes_store_methods
assert_equal __, MailTruck.instance_methods.include?(:driver)
- end
-
+ end
+
=begin
BasicObject
@@ -52,14 +52,14 @@ def test_classes_store_methods
|
Class
-=end
-
+=end
+
def test_class_is_an_object
assert_equal __, Class.is_a?(Object)
assert_equal __, Class.superclass
assert_equal __, Class.superclass.superclass
end
-
+
def test_class_has_object_id
assert_equal __, @truck.object_id > 0
assert_equal __, MailTruck.object_id > 0
@@ -68,7 +68,7 @@ def test_class_has_object_id
def test_Object_class_is_Class
assert_equal __, Object.class
end
-
+
def test_Object_inherits_from_Basic_Object
assert_equal __, Object.superclass
end
@@ -82,17 +82,17 @@ def has_mail?
!(@mails.nil? || @mails.empty?)
end
end
-
+
def test_metaclass_is_a_class_which_an_object_uses_to_redefine_itself
assert_equal __, @truck.has_mail?
end
-
+
class ::Class
def is_everything_an_object?
true
end
end
-
+
def test_metaclass_is_a_class_which_even_Class_uses_to_redefine_itself
assert_equal __, Class.is_everything_an_object?
assert_equal __, MailTruck.is_everything_an_object?
@@ -110,7 +110,7 @@ def red_truck.honk
blue_truck.honk
end
end
-
+
=begin
MailTruck
@@ -118,13 +118,13 @@ def red_truck.honk
Metaclass
|
@truck
-
+
=end
def test_metaclass_sits_between_object_and_class
assert_equal __, @truck.metaclass.superclass
end
-
+
def test_singleton_methods_are_defined_in_metaclass
def @truck.honk
"Honk"
@@ -133,14 +133,14 @@ def @truck.honk
assert_equal __, @truck.metaclass.instance_methods.include?(:honk)
assert_equal __, @truck.singleton_methods.include?(:honk)
end
-
+
class ::Object
def metaclass
class << self ; self ; end
end
end
-
- def test_class_lt_lt_m_opens_up_metaclass
+
+ def test_class_lt_lt_opens_up_metaclass
klass = class << @truck ; self ; end
assert_equal __, klass == @truck.metaclass
end
@@ -149,7 +149,7 @@ def test_metaclass_can_have_metaclass_ad_infinitum
assert_equal __, @truck.metaclass.metaclass.nil?
assert_equal __, @truck.metaclass.metaclass.metaclass.nil?
end
-
+
def test_metaclass_of_a_metaclass_does_not_affect_the_original_object
def @truck.honk
"Honk"
@@ -159,14 +159,14 @@ def @truck.honk
def metaclass.honk_honk
"Honk Honk"
end
-
+
assert_equal __, @truck.honk
assert_equal __, @truck.meta_eval { honk_honk }
assert_raises(NoMethodError) do
@truck.honk_honk
end
end
-
+
=begin
MailTruck
|
@@ -186,7 +186,7 @@ def MailTruck.count_trucks
@@trucks.count
end
end
-
+
def test_classes_can_have_class_variables
red_truck = MailTruck.new
blue_truck = MailTruck.new
@@ -195,17 +195,17 @@ def test_classes_can_have_class_variables
assert_equal __, MailTruck.count_trucks
end
-
+
class MailTruck
@trucks = []
-
+
def MailTruck.add_a_truck(truck)
@trucks << truck
end
def MailTruck.total_trucks
@trucks.count
- end
+ end
end
def test_classes_can_have_instance_variables
@@ -228,12 +228,12 @@ def say_hi
"Hi! I'm one of #{@@trucks.length} trucks"
end
end
-
+
def test_only_class_variables_can_be_accessed_by_instances_of_class
MailTruck.add_truck(@truck)
assert_equal __, @truck.say_hi
end
-
+
def test_class_methods_are_defined_in_metaclass_of_class
assert_equal __, MailTruck.metaclass.instance_methods.include?(:add_truck)
assert_equal __, MailTruck.metaclass.instance_methods.include?(:add_a_truck)
@@ -244,16 +244,16 @@ def self.add_another_truck(truck)
@@trucks << truck
end
end
-
+
def test_class_methods_can_also_be_defined_using_self
MailTruck.add_another_truck(MailTruck.new)
assert_equal __, MailTruck.count_trucks
end
-
+
def test_all_class_methods_are_defined_in_metaclass_of_class
assert_equal __, MailTruck.metaclass.instance_methods.include?(:add_another_truck)
end
-
+
class ::Object
def meta_eval(&block)
metaclass.instance_eval(&block)
@@ -263,7 +263,7 @@ def meta_def name, &block
meta_eval { define_method name, &block }
end
end
-
+
class MailTruck
def self.made_by(name)
meta_def :company do
@@ -275,23 +275,23 @@ def self.made_by(name)
class ManualTruck < MailTruck
made_by "TrucksRUs"
end
-
+
class RobotTruck < MailTruck
made_by "Lego"
end
-
+
def test_meta_def_can_be_used_to_add_methods_dynamically_to_metaclass
assert_equal __, ManualTruck.company
assert_equal __, RobotTruck.company
end
-
+
class ::Object
# Defines an instance method within a class
def class_def name, &block
class_eval { define_method name, &block }
end
end
-
+
class MailTruck
def self.check_for(attr)
class_def :can_drive? do
@@ -303,7 +303,7 @@ def self.check_for(attr)
class ManualTruck < MailTruck
check_for :driver
end
-
+
class RobotTruck < MailTruck
check_for :route
end
@@ -312,24 +312,24 @@ def test_class_def_can_be_used_to_add_instance_methods_dynamically
assert_equal __, ManualTruck.new.can_drive?
assert_equal __, RobotTruck.new.can_drive?
- assert_equal __, ManualTruck.new('Harold', nil).can_drive?
+ assert_equal __, ManualTruck.new('Harold', nil).can_drive?
assert_equal __, RobotTruck.new(nil, ['SF']).can_drive?
end
-
+
class ::Object
def meta_eval(&block)
metaclass.instance_eval(&block)
end
-
+
# Add methods to metaclass
def meta_def name, &block
meta_eval { define_method name, &block }
end
-
+
# Defines an instance method within a class
def class_def name, &block
class_eval { define_method name, &block }
end
end
-
+
end
View
84 src/about_metaclass.rb
@@ -4,7 +4,7 @@
# http://dannytatom.github.com/metaid/
class AboutMetaclass < EdgeCase::Koan
-
+
class MailTruck
attr_accessor :driver, :route
def initialize(driver = nil, route = nil)
@@ -13,9 +13,9 @@ def initialize(driver = nil, route = nil)
end
def setup
- @truck = MailTruck.new("Harold", ['12 Corrigan way', '23 Antler Ave'])
+ @truck = MailTruck.new("Harold", ['12 Corrigan way', '23 Antler Ave'])
end
-
+
def test_class_of_an_object
assert_equal MailTruck, @truck.class
end
@@ -23,7 +23,7 @@ def test_class_of_an_object
def test_class_of_a_class
assert_equal Class, MailTruck.class
end
-
+
def test_object_is_a_storage_for_variables
assert_equal "Harold", @truck.driver
end
@@ -40,8 +40,8 @@ def test_attr_accessor_defines_reader_and_writer
def test_classes_store_methods
assert_equal true, MailTruck.instance_methods.include?(:driver)
- end
-
+ end
+
=begin
BasicObject
@@ -52,14 +52,14 @@ def test_classes_store_methods
|
Class
-=end
-
+=end
+
def test_class_is_an_object
assert_equal true, Class.is_a?(Object)
assert_equal Module, Class.superclass
assert_equal Object, Class.superclass.superclass
end
-
+
def test_class_has_object_id
assert_equal true, @truck.object_id > 0
assert_equal true, MailTruck.object_id > 0
@@ -68,7 +68,7 @@ def test_class_has_object_id
def test_Object_class_is_Class
assert_equal Class, Object.class
end
-
+
def test_Object_inherits_from_Basic_Object
assert_equal BasicObject, Object.superclass
end
@@ -82,17 +82,17 @@ def has_mail?
!(@mails.nil? || @mails.empty?)
end
end
-
+
def test_metaclass_is_a_class_which_an_object_uses_to_redefine_itself
assert_equal false, @truck.has_mail?
end
-
+
class ::Class
def is_everything_an_object?
true
end
end
-
+
def test_metaclass_is_a_class_which_even_Class_uses_to_redefine_itself
assert_equal true, Class.is_everything_an_object?
assert_equal true, MailTruck.is_everything_an_object?
@@ -110,7 +110,7 @@ def red_truck.honk
blue_truck.honk
end
end
-
+
=begin
MailTruck
@@ -118,13 +118,13 @@ def red_truck.honk
Metaclass
|
@truck
-
+
=end
def test_metaclass_sits_between_object_and_class
assert_equal MailTruck, @truck.metaclass.superclass
end
-
+
def test_singleton_methods_are_defined_in_metaclass
def @truck.honk
"Honk"
@@ -133,14 +133,14 @@ def @truck.honk
assert_equal true, @truck.metaclass.instance_methods.include?(:honk)
assert_equal true, @truck.singleton_methods.include?(:honk)
end
-
+
class ::Object
def metaclass
class << self ; self ; end
end
end
-
- def test_class_lt_lt_m_opens_up_metaclass
+
+ def test_class_lt_lt_opens_up_metaclass
klass = class << @truck ; self ; end
assert_equal true, klass == @truck.metaclass
end
@@ -149,7 +149,7 @@ def test_metaclass_can_have_metaclass_ad_infinitum
assert_equal false, @truck.metaclass.metaclass.nil?
assert_equal false, @truck.metaclass.metaclass.metaclass.nil?
end
-
+
def test_metaclass_of_a_metaclass_does_not_affect_the_original_object
def @truck.honk
"Honk"
@@ -159,14 +159,14 @@ def @truck.honk
def metaclass.honk_honk
"Honk Honk"
end
-
+
assert_equal "Honk", @truck.honk
assert_equal "Honk Honk", @truck.meta_eval { honk_honk }
assert_raises(NoMethodError) do
@truck.honk_honk
end
end
-
+
=begin
MailTruck
|
@@ -186,7 +186,7 @@ def MailTruck.count_trucks
@@trucks.count
end
end
-
+
def test_classes_can_have_class_variables
red_truck = MailTruck.new
blue_truck = MailTruck.new
@@ -195,17 +195,17 @@ def test_classes_can_have_class_variables
assert_equal 2, MailTruck.count_trucks
end
-
+
class MailTruck
@trucks = []
-
+
def MailTruck.add_a_truck(truck)
@trucks << truck
end
def MailTruck.total_trucks
@trucks.count
- end
+ end
end
def test_classes_can_have_instance_variables
@@ -228,12 +228,12 @@ def say_hi
"Hi! I'm one of #{@@trucks.length} trucks"
end
end
-
+
def test_only_class_variables_can_be_accessed_by_instances_of_class
MailTruck.add_truck(@truck)
assert_equal "Hi! I'm one of 3 trucks", @truck.say_hi
end
-
+
def test_class_methods_are_defined_in_metaclass_of_class
assert_equal true, MailTruck.metaclass.instance_methods.include?(:add_truck)
assert_equal true, MailTruck.metaclass.instance_methods.include?(:add_a_truck)
@@ -244,16 +244,16 @@ def self.add_another_truck(truck)
@@trucks << truck
end
end
-
+
def test_class_methods_can_also_be_defined_using_self
MailTruck.add_another_truck(MailTruck.new)
assert_equal 4, MailTruck.count_trucks
end
-
+
def test_all_class_methods_are_defined_in_metaclass_of_class
assert_equal true, MailTruck.metaclass.instance_methods.include?(:add_another_truck)
end
-
+
class ::Object
def meta_eval(&block)
metaclass.instance_eval(&block)
@@ -263,7 +263,7 @@ def meta_def name, &block
meta_eval { define_method name, &block }
end
end
-
+
class MailTruck
def self.made_by(name)
meta_def :company do
@@ -275,23 +275,23 @@ def self.made_by(name)
class ManualTruck < MailTruck
made_by "TrucksRUs"
end
-
+
class RobotTruck < MailTruck
made_by "Lego"
end
-
+
def test_meta_def_can_be_used_to_add_methods_dynamically_to_metaclass
assert_equal "TrucksRUs", ManualTruck.company
assert_equal "Lego", RobotTruck.company
end
-
+
class ::Object
# Defines an instance method within a class
def class_def name, &block
class_eval { define_method name, &block }
end
end
-
+
class MailTruck
def self.check_for(attr)
class_def :can_drive? do
@@ -303,7 +303,7 @@ def self.check_for(attr)
class ManualTruck < MailTruck
check_for :driver
end
-
+
class RobotTruck < MailTruck
check_for :route
end
@@ -312,24 +312,24 @@ def test_class_def_can_be_used_to_add_instance_methods_dynamically
assert_equal false, ManualTruck.new.can_drive?
assert_equal false, RobotTruck.new.can_drive?
- assert_equal true, ManualTruck.new('Harold', nil).can_drive?
+ assert_equal true, ManualTruck.new('Harold', nil).can_drive?
assert_equal true, RobotTruck.new(nil, ['SF']).can_drive?
end
-
+
class ::Object
def meta_eval(&block)
metaclass.instance_eval(&block)
end
-
+
# Add methods to metaclass
def meta_def name, &block
meta_eval { define_method name, &block }
end
-
+
# Defines an instance method within a class
def class_def name, &block
class_eval { define_method name, &block }
end
end
-
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.