mirror of
https://github.com/PeterCamilleri/fOOrth
synced 2024-11-16 07:47:56 +01:00
Monkey patched in the foorth_name method so that now, all objects
understand that method.
This commit is contained in:
parent
30e4e36061
commit
1a37963c12
4 changed files with 26 additions and 1 deletions
|
@ -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'
|
||||
|
|
14
lib/fOOrth/monkey_patch/class.rb
Normal file
14
lib/fOOrth/monkey_patch/class.rb
Normal 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
|
|
@ -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}"
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue