Project

General

Profile

Feature #4893 ยป StringInit.rb

lazaridis.com (Lazaridis Ilias), 06/26/2011 04:54 PM

 
1
#!/usr/bin/env ruby
2

    
3
class String
4
  @@running_counter = 0
5
  def initialize(val)
6
    @@running_counter += 1
7
  end
8

    
9
  def self.running_counter
10
    @@running_counter
11
  end
12
end
13

    
14
puts String.call_initialize == FALSE
15

    
16
String.call_initialize = TRUE
17
puts String.call_initialize == TRUE
18

    
19
p String.running_counter
20

    
21
oo_string = String.new("The OO String 1")
22
p String.running_counter 
23

    
24
li_string = "The Literal String 2"
25
p String.running_counter 
26

    
27
oo_string = String.new("The OO String 3")
28
p String.running_counter 
29

    
30
String.call_initialize = FALSE
31
puts String.call_initialize == FALSE
32

    
33
li_string = "The Literal String 4"
34
p String.running_counter 
35

    
36
li_string = 'The Literal String 5'
37
p String.running_counter
38

    
39
String.call_initialize = TRUE
40
puts String.call_initialize == TRUE
41

    
42
puts "Print Literal"
43
p String.running_counter