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.
Written by Denis Savitskiy
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#