I understand or equal to operation in ruby but can you explain what you have done with:
Object.const_get("#{obj.class}Park").new(obj)
In ruby, something that starts with a capital letter is a constant. Here is a simpler example of how const_get() works:
class Dog def bark puts 'woof' end end dog_class = Object.const_get("Dog") dog_class.new.bark --output:-- woof
Of course, you can also pass arguments to dog_class.new:
class Dog attr_reader :name def initialize(name) @name = name end def bark puts "#{name} says woof!" end end dog_class = Object.const_get("Dog") dog_class.new('Ralph').bark --output:-- Ralph says woof!
And the following line is just a variation of the above:
Object.const_get("#{obj.class}Park").new(obj)
If obj = 'hello', the first portion:
Object.const_get("#{obj.class}Park")
is equivalent to:
Object.const_get("#{String}Park")
And when the String class object is interpolated into a string, it is simply converted to the string "String", giving you:
Object.const_get("StringPark")
And that line retrieves the StringPark class, giving you:
Object.const_get("StringPark") | V StringPark
Then, adding the second portion of the original line gives you:
StringPark.new(obj)
And because obj = 'hello', that is equivalent to:
StringPark.new('hello')
Capice?
ishould produce its own results--rather than park() calculating the result based oni's type.