Guest User

Untitled

a guest
Sep 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class Employee
  2. attr_accessor :name
  3. def self.new_with_name(name)
  4. output = self.new
  5. output.name = name
  6. return output
  7. end
  8. end
  9.  
  10. # List all methods on the employee class and sort them
  11. Employee.methods.sort
  12. => [... "new_with_name", ...]
  13.  
  14. # Use the class method to create a new employee with a name
  15. e = Employee.new_with_name(“Michael Koby”)
  16.  
  17. e.name # => "Michael Koby"
  18.  
  19. # List all methods available on the object created with the class method
  20. e.methods.sort
  21. => [...] #doesn't contain the new_with_name method because it's a CLASS method
Add Comment
Please, Sign In to add comment