Here's a code sample:
class Book
def initialize
@v = "abc"
end
end
b = Book.new
b.instance_eval do
def book_name
end
end
Why do we use instance_eval to create a method (book_name) instead of adding book_name method inside class Book? The method (book_name) created using instance_eval will be accessible only by object b in the case above. Is there any particular use case?
Class Booktoclass Book.