Send allows you to call a method identified by a symbol.

My app has classes for people and events. Each class has different attributes.

class Person
attr_accessor :name
class Event
attr_accessor :title

I also have a module which sets up the objects.

module Setup
def init(name_or_title)

Exercise - Send a little love

Include the Setup module in the Person and Item classes. Now write the init method. use respond_to? and send to initialise either the name or title.

Start with an array [:name, :title], then iterate over it, checking if the object responds to the methods, then call the method when you get a result.

Do you like Email? Do You Like JavaScript?

Sign up for occasional emails covering modern Web Development topics such as Angular 2 and React. You can unsubscribe at any time.

We totally respect your email privacy

comments powered by Disqus