Project

General

Profile

Feature #4893 » StringInit.rb

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

 
#!/usr/bin/env ruby

class String
@@running_counter = 0
def initialize(val)
@@running_counter += 1
end

def self.running_counter
@@running_counter
end
end

puts String.call_initialize == FALSE

String.call_initialize = TRUE
puts String.call_initialize == TRUE

p String.running_counter

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

li_string = "The Literal String 2"
p String.running_counter

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

String.call_initialize = FALSE
puts String.call_initialize == FALSE

li_string = "The Literal String 4"
p String.running_counter

li_string = 'The Literal String 5'
p String.running_counter

String.call_initialize = TRUE
puts String.call_initialize == TRUE

puts "Print Literal"
p String.running_counter
(4-4/13)