On Wed, Apr 05, 2006 at 05:39:35PM -0400, Jason T. wrote:
} I’m trying to write some methods which use a parameter to represent a
} Class name.
}
} A very simplistic example:
}
} def foo(class_name, conditions)
} x = class_name.find(:all, :conditions => “#{conditions}”)
} end
}
} Unfortunately, this does not work. The only way around this problem
} that I can think of is to use eval:
[…]
} There’s got to be a better way. – Please help!
def foo(class_name, conditions)
x = Kernel.const_get(class_name).find(:all, :conditions =>
“#{conditions}”)
end
On Thu, Apr 06, 2006 at 02:08:21AM +0200, carmen wrote:
}
} >> def foo(class_name, conditions)
} >> x = Kernel.const_get(class_name).find(:all, :conditions => "#
}
} ive been using Object’s const_get instead of Kernel’s. is there a
} difference? and why is there an object and a kernel if not?