0Pricing
Ruby Academy · Lesson

Using send and eval

Discover how to execute dynamic method calls and evaluate strings as Ruby code.

1

Using send and eval

Ruby provides powerful methods like send and eval to dynamically execute code.

These methods allow calling methods dynamically and evaluating Ruby expressions at runtime.

Using send and eval — illustration 1

2

What is the send Method?

send allows calling methods dynamically by name.

It can invoke private and public methods.

class Person
  def greet
    'Hello!'
  end
end

p = Person.new
puts p.send(:greet)

All lessons in this course

  1. What is Metaprogramming?
  2. Dynamic Method Definition
  3. Open Classes and Monkey Patching
  4. Using send and eval
← Back to Ruby Academy