I'm reading my ruby book. Looking at the code below,
module Destroy
def destroy(anyObject)
@anyObject = anyObject
puts "I will destroy the object: #{anyObject}"
end
end
class User
include Destroy
attr_accessor :name, :email
def initialize(name,email)
@name = name
@email = email
end
end
my_info = User.new("Bob","Bob@example.com")
puts "So your name is: #{my_info.name} and you have email #{my_info.email}"
user = User.new("john","john@example.com")
user.destroy("blah")
I could've just created another method inside my class. Why would I want to do this? Why would I want to use a module? It's not like embedding this into other classes is any easier than just using normal inheritance.