Monkey patched in the foorth_name method so that now, all objects

understand that method.
This commit is contained in:
Peter Camilleri 2014-11-08 16:59:39 -05:00
parent 30e4e36061
commit 1a37963c12
4 changed files with 26 additions and 1 deletions

View file

@ -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'

View file

@ -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

View file

@ -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}"

View file

@ -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