diff --git a/lib/fOOrth/monkey_patch.rb b/lib/fOOrth/monkey_patch.rb index af04c1d..ddaa0ad 100644 --- a/lib/fOOrth/monkey_patch.rb +++ b/lib/fOOrth/monkey_patch.rb @@ -3,6 +3,7 @@ #A collection of standard library monkey patches required by foorth. require_relative 'monkey_patch/object' +require_relative 'monkey_patch/class' require_relative 'monkey_patch/numeric' require_relative 'monkey_patch/rational' require_relative 'monkey_patch/complex' diff --git a/lib/fOOrth/monkey_patch/class.rb b/lib/fOOrth/monkey_patch/class.rb new file mode 100644 index 0000000..f19c1ca --- /dev/null +++ b/lib/fOOrth/monkey_patch/class.rb @@ -0,0 +1,14 @@ +# coding: utf-8 + +#Extensions to the \Class class required by the fOOrth language system. +# coding: utf-8 + +#Extensions to the \Object class required by the fOOrth language system. +class Class + + #Get the foorth name of this class. Note: test located in object_tests.rb + def foorth_name + "Ruby::#{self.name}" + end + +end diff --git a/lib/fOOrth/monkey_patch/object.rb b/lib/fOOrth/monkey_patch/object.rb index 7d8ac80..fea7750 100644 --- a/lib/fOOrth/monkey_patch/object.rb +++ b/lib/fOOrth/monkey_patch/object.rb @@ -2,6 +2,11 @@ #Extensions to the \Object class required by the fOOrth language system. class Object + #Get the foorth name of this object. + def foorth_name + "#{self.class.foorth_name} instance" + end + #Raise a fOOrth language internal exception as this operation is not allowed. def embed error "Can't embed class #{self.class.to_s}" diff --git a/tests/monkey_patch/object_test.rb b/tests/monkey_patch/object_test.rb index 90fbe54..a7f6ece 100644 --- a/tests/monkey_patch/object_test.rb +++ b/tests/monkey_patch/object_test.rb @@ -1,7 +1,7 @@ # coding: utf-8 require_relative '../../lib/fOOrth/exceptions' -require_relative '../../lib/fOOrth/monkey_patch/object' +require_relative '../../lib/fOOrth/monkey_patch' require 'minitest/autorun' #A tiny test class used to test access to instance variables. @@ -76,4 +76,9 @@ class ObjectMonkeyPatchTester < MiniTest::Unit::TestCase assert_equal(test.read_var(:@my_var), "after") end + def test_object_naming + assert_equal("Ruby::Object", Object.foorth_name) + assert_equal("Ruby::Regexp instance", (/ABC/).foorth_name) + end + end \ No newline at end of file