Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Employee
- attr_accessor :name
- def self.new_with_name(name)
- output = self.new
- output.name = name
- return output
- end
- end
- # List all methods on the employee class and sort them
- Employee.methods.sort
- => [... "new_with_name", ...]
- # Use the class method to create a new employee with a name
- e = Employee.new_with_name(“Michael Koby”)
- e.name # => "Michael Koby"
- # List all methods available on the object created with the class method
- e.methods.sort
- => [...] #doesn't contain the new_with_name method because it's a CLASS method
Add Comment
Please, Sign In to add comment