Last Updated: February 25, 2016
·
1.238K
· sadfuzzy

Call Ruby gently by name

Call class by name:

class_name = 'Integer'
class = Kernel.const_get(class_name) # => Integer
class.methods # calls Integer.methods

Call method by name:

str = "Call me, dear!"
len = str.method(:length) # or str.method("length")
len.call # => 14

I've written 'call' method, because it's very fast.