fOOrth 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@ module XfOOrth
13
13
  # [name Thread] .new{{ ... }} [a_thread]
14
14
  Thread.create_exclusive_method('.new{{', NosSpec, [], &lambda {|vm|
15
15
  block = vm.pop
16
- name = vm.pop.to_s
16
+ name = vm.pop.to_s.freeze
17
17
  vm.push(block.do_thread_start(vm, name))
18
18
  })
19
19
 
@@ -6,7 +6,7 @@ module XfOOrth
6
6
  #Get the VM as a string.
7
7
  # [vm] .to_s ["vm as a string"]
8
8
  VirtualMachine.create_shared_method('.to_s', TosSpec, [],
9
- &lambda {|vm| vm.push(self.foorth_name)})
9
+ &lambda {|vm| vm.push(self.foorth_name.freeze)})
10
10
 
11
11
  #Create a macro to get at the current virtual machine instance.
12
12
  # [] vm [the_current_vm]
@@ -6,7 +6,7 @@ class Numeric
6
6
  #<br>Returns
7
7
  #* An embeddable form of this number as a string.
8
8
  def foorth_embed
9
- self.to_s
9
+ self.to_s.freeze
10
10
  end
11
11
 
12
12
  #Convert this number to a single character string.
@@ -28,6 +28,11 @@ class Object
28
28
  nil
29
29
  end
30
30
 
31
+ #Freeze only pure strings
32
+ def foorth_string_freeze
33
+ self
34
+ end
35
+
31
36
  #Fail with XfOOrthError argument error.
32
37
  def error(msg)
33
38
  fail XfOOrth::XfOOrthError, msg, caller
@@ -13,7 +13,7 @@ class String
13
13
  #<br>Endemic Code Smells
14
14
  #* :reek:FeatureEnvy -- false positive
15
15
  def foorth_coerce(arg)
16
- arg.to_s
16
+ arg.to_s.freeze
17
17
  rescue
18
18
  error "F40: Cannot coerce a #{arg.foorth_name} to an String instance"
19
19
  end
@@ -48,4 +48,61 @@ class String
48
48
  self.to_foorth_n.to_foorth_r
49
49
  end
50
50
 
51
+ #A special patch for safe_clone
52
+ def safe_clone
53
+ self.freeze
54
+ end
55
+
56
+ #A special patch for full_clone
57
+ def full_clone(_arg=nil)
58
+ self.freeze
59
+ end
60
+
61
+ #Freeze only pure strings
62
+ def foorth_string_freeze
63
+ self.freeze
64
+ end
65
+
66
+ #Create an instance of a String.
67
+ #<br>Parameters:
68
+ #* vm - The current fOOrth virtual machine.
69
+ def self.create_foorth_instance(vm)
70
+ (obj = "".freeze).foorth_init(vm)
71
+ obj
72
+ end
73
+
74
+ end
75
+
76
+ #The \StringBuffer class is the mutable variant of the String class.
77
+ class StringBuffer < String
78
+
79
+ #Create a string buffer from an object. Make sure that object is a
80
+ #string and make sure that string is not frozen.
81
+ def initialize(text="")
82
+ super(text)
83
+ end
84
+
85
+ #A special patch for safe_clone
86
+ def safe_clone
87
+ self.clone
88
+ end
89
+
90
+ #A special patch for full_clone
91
+ def full_clone(_arg=nil)
92
+ self.clone
93
+ end
94
+
95
+ #Freeze only pure strings
96
+ def foorth_string_freeze
97
+ self
98
+ end
99
+
100
+ #Create an instance of StringBuffer.
101
+ #<br>Parameters:
102
+ #* vm - The current fOOrth virtual machine.
103
+ def self.create_foorth_instance(vm)
104
+ (obj = self.new).foorth_init(vm)
105
+ obj
106
+ end
107
+
51
108
  end
@@ -3,5 +3,5 @@
3
3
  #* version.rb - The version string for fOOrth.
4
4
  module XfOOrth
5
5
  #The version string for fOOrth.
6
- VERSION = "0.5.3"
6
+ VERSION = "0.6.0"
7
7
  end
@@ -46,8 +46,16 @@ class StringMonkeyPatchTester < Minitest::Test
46
46
  def test_to_rational
47
47
  assert_equal(Rational(1,2), '1/2'.to_foorth_r)
48
48
  assert_equal(nil, 'apple'.to_foorth_r)
49
-
50
49
  end
51
50
 
51
+ def test_clone_patches
52
+ s = "abc"
53
+ assert_equal(s.object_id, s.safe_clone.object_id)
54
+ assert_equal(s.object_id, s.full_clone.object_id)
55
+
56
+ b = StringBuffer.new('abc')
57
+ refute_equal(b.object_id, b.safe_clone.object_id)
58
+ refute_equal(b.object_id, b.full_clone.object_id)
59
+ end
52
60
 
53
- end
61
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fOOrth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Camilleri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-07 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler