Hi,
When I run the code at the end of the message it all works as expected
but I get a warning :
workpad2.rb:3: warning: Object#type is deprecated; use Object#class
This is casued by the first line in the BaseClass.initialize method,
because I use the type property to get to actual type of the class
instance. If I use the “class” property as suggested in the warning,
the code actually fails to compile with the following :
workpad2.rb:3: parse error, unexpected ‘.’
if(!class.isMatch(input))
^
This occurs when I change the initialize method to use the “class”
accessor:
def initialize(input)
if(!class.isMatch(input))
raise "Invalid input provided"
end
end
Any advice? Should I just ignore the warning and go-ahead and use the
“type” accessor?
Nick.
The code is:
class BaseClass
def initialize(input)
if(!type.isMatch(input))
raise “Invalid input provided”
end
end
end
class AClass < BaseClass
def initialize(input)
super(input)
end
def self.isMatch(input)
puts "AClass::invoked"
input =~ "1"
end
end
class BClass < BaseClass
def initialize(input)
super(input)
end
def self.isMatch(input)
puts “BClass::invoked”
input == “2”
end
end
bclass = BClass.new(“2”)
puts “here”