mirror of
https://github.com/PeterCamilleri/fOOrth
synced 2024-11-16 07:47:56 +01:00
Added the .to_s and .strlen methods.
This commit is contained in:
parent
53e0a3774c
commit
730c4ada7c
3 changed files with 22 additions and 0 deletions
|
@ -35,4 +35,11 @@ class ObjectLibraryTester < MiniTest::Unit::TestCase
|
|||
foorth_equal('"Foobar" .name', ['String instance'])
|
||||
end
|
||||
|
||||
def test_getting_an_object_as_a_string
|
||||
foorth_equal("4 .to_s", ['4'])
|
||||
foorth_equal("Object .to_s", ['Object'])
|
||||
foorth_equal("VirtualMachine .to_s", ['VirtualMachine'])
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -8,6 +8,11 @@ module XfOOrth
|
|||
Class.create_shared_method('.new', TosSpec, [],
|
||||
&lambda {|vm| vm.push(self.create_foorth_instance(vm)); })
|
||||
|
||||
#Get the class as a string.
|
||||
# [cls] .to_s ["cls as a string"]
|
||||
Class.create_shared_method('.to_s', TosSpec, [],
|
||||
&lambda {|vm| vm.push(self.foorth_name)})
|
||||
|
||||
#The .parent_class method. Retrieves the parent class of a class.
|
||||
# [a_class] .parent_class [parent_class or nil]
|
||||
Class.create_shared_method('.parent_class', TosSpec, [],
|
||||
|
|
|
@ -18,6 +18,16 @@ module XfOOrth
|
|||
Object.create_shared_method('.name', TosSpec, [],
|
||||
&lambda {|vm| vm.push(self.foorth_name)})
|
||||
|
||||
#Get the object as a string.
|
||||
# [obj] .to_s ["obj as a string"]
|
||||
Object.create_shared_method('.to_s', TosSpec, [],
|
||||
&lambda {|vm| vm.push(self.to_s)})
|
||||
|
||||
#Get the length of the object as a string.
|
||||
# [obj] .strlen [n]; the length of the object's to_s string
|
||||
Object.create_shared_method('.strlen', TosSpec, [],
|
||||
&lambda {|vm| vm.push(self.to_foorth_s.length)})
|
||||
|
||||
# Some boolean operation words.
|
||||
# [b,a] && [b&a]
|
||||
Object.create_shared_method('&&', TosSpec, [],
|
||||
|
|
Loading…
Reference in a new issue