head_first_ruby4_initializing_instances.rb
#setting the @name & @salary instance variables - now an initialize method is set up already set up for new Employee instance, safe to call print_pay_stub on them
#sets a defaul of Anonymous & 0 -use name parameter to set @name isntance variable, use salary parameter to set @salary instance variable
#Be careful not pass new arguments to new - will be no arguments to forward on to initialize
#Can have best of both worlds to initialize in an ordinary method to utilize feaures of an ordinary method with optional parameters- allows you to call both employee.new & specific names of employees also.
#using self. states that we definitely want to make a call to the "name" method & "salary" method
#means that the validation code works without duplicating code
setting the @name & @salary instance variables - now an initialize method is set up already set up for new Employee instance, safe to call print_pay_stub on them
sets a defaul of Anonymous & 0 -use name parameter to set @name isntance variable, use salary parameter to set @salary instance variable
Be careful not pass new arguments to new - will be no arguments to forward on to initialize
Can have best of both worlds to initialize in an ordinary method to utilize feaures of an ordinary method with optional parameters- allows you to call both employee.new & specific names of employees also.
using self. states that we definitely want to make a call to the "name" method & "salary" method
means that the validation code works without duplicating code
setting the @name & @salary instance variables - now an initialize method is set up already set up for new Employee instance safe to call print_pay_stub on them sets a defaul of Anonymous & 0 - use name parameter to set @name isntance variable use salary parameter to set @salary instance variable Be careful not pass new arguments to new - will be no arguments to forward on to initialize Can have best of both worlds to initialize in an ordinary method to utilize feaures of an ordinary method with optional parameters - allows you to call both employee . new & specific names of employees also . using self . states that we definitely want to make a call to the " name " method & " salary " method means that the validation code works without duplicating code
def print_pay_stub
    puts "Name: #{name}"
    pay_for_period = (salary / 365.0) * 14 
    formatted_pay = format("%.2f", pay_for_period) 
    puts "Pay This Period: $#{formatted_pay}" 
  end
def print_pay_stub puts "Name: #{name}" pay_for_period = ( salary / 365.0 ) * 14 formatted_pay = format ( "%.2f" , pay_for_period ) puts "Pay This Period: $#{formatted_pay}" end
setting the @name & @salary instance variables - now an initialize method is set up already set up for new Employee instance, safe to call print_pay_stub on them
sets a defaul of Anonymous & 0 -use name parameter to set @name isntance variable, use salary parameter to set @salary instance variable
Be careful not pass new arguments to new - will be no arguments to forward on to initialize
Can have best of both worlds to initialize in an ordinary method to utilize feaures of an ordinary method with optional parameters- allows you to call both employee.new & specific names of employees also.
setting the @name & @salary instance variables - now an initialize method is set up already set up for new Employee instance safe to call print_pay_stub on them sets a defaul of Anonymous & 0 - use name parameter to set @name isntance variable use salary parameter to set @salary instance variable Be careful not pass new arguments to new - will be no arguments to forward on to initialize Can have best of both worlds to initialize in an ordinary method to utilize feaures of an ordinary method with optional parameters - allows you to call both employee . new & specific names of employees also .
#could use self.salary & self & self.name but self is optional here & works wihout them #get a string with pay amount rounded to 2 decimal places #print formatted string amount