I have this class:
class User < ActiveRecord::Base
attr_accessor :name, :email, :hr_id
def initialize(attributes = {:name => "Missing Name",:email => "Missing Email",:hr_id => "Missing HR ID"})
@name = attributes[:name]
@email = attributes[:email]
@hr_id = attributes[:hr_id]
end
def print_employee
"Employee No: #{@hr_id} - #{@name} (#{@email})"
end
end
And i use it like this:
def help
employee = User.new
employee.name = "Dude"
employee.email = "Dude@gmail.com"
employee.hr_id = "129836561"
@employee = employee.print_employee
end
My question is, how can i make the code in help
shorter and more elegant?
I tried:
employee = User.new('dude','dude@gmail.com','129836561')
@employee = employee.print_employee
But i got errors.